print(function(a, b){
	var i, l, ans=-1e20, t=-1;

	if(b===0){
		ans=[];
		for(i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}

	for(i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;
	var sb1=repeat(bx+1, 'x');
	var sb2=repeat(bx, 'x');

	var ans2='';
	for(i=0; i<t; i++){
		ans2+= (i<bi?sb1:sb2)+(i<ai?'o':i===ai?repeat(ax, 'o'):'');
	}
	return ans+'\n'+ans2;
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}


print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;
	var aa=[];
	var bb=[];
	var sb=[];
	for(var i=0; i<bi; i++){
		bb.push(repeat(bx+1, 'x'));
	}
	for(var i=0; i<b-bi; i++){
		bb.push(repeat(bx, 'x'));
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}


print(function(a, b){

	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var x=(a-i)*(a-i)+i  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	if(a!==0){
		for(var j=0; j<a-t+1; j++){
			sa.push('o');
		}
	}
	// print(t)
	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));


print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i-1;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t-1;
	var ax=a-ai;
	var aa=[];
	var bb=[];
	var sb=[];
	for(var i=0; i<bi; i++){
		bb.push(repeat(bx+1, 'x'));
	}
	for(var i=0; i<b-bi; i++){
		bb.push(repeat(bx, 'x'));
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	long long int a , b, a2, b2;
	cin >> a >> b;
	if(a < b){
		cout << -1*(b-a)*(b-a) << endl;
		for(int i = 0 ; i < a ; i++) cout <<"xo";

		for(int i = 0 ; i < b-a; i++) cout <<"x";
		cout << endl;
	} else {
		//a2 = a*a;
		//b2 = b*b;
		a2 = (a-1)*(a-1);
		b2 = ( ((b+1)/2)*((b+1)/2) + (b/2)*(b/2) );
		if(a*a-b*b > a2-b2+1){
			cout << a*a-b*b << endl;
			for(int i = 0 ; i < a ; i++) cout <<"o";
			for(int i = 0 ; i < b ; i++) cout <<"x";
			cout << endl;
		}else {
			cout << a2 - b2 + 1 << endl;
			for(int i = 0 ; i < a-1 ; i++) cout << "o";

			for(int i = 0 ; i < (b+1)/2 ; i++) cout << "x";

			cout << "o";

			for(int i = 0 ; i < b/2 ; i++) cout << "x";

			cout << endl;
		}
	}

	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

long long int parts(long long int m , int k){
	long long int x = m/k;
	long long int y = m%k;

	return y*(x+1)*(x+1) + (k-y)*x*x;
}
int main(){
	long long int a , b, a2, b2;
	cin >> a >> b;
	if(!a){
		cout << -1*b*b << endl;
		for(int i = 0 ; i < b ; i++) cout << "x";
		cout << endl;
		return 0;
	}
	long long int m = -(1LL<<62);
	long long int tmp;
	int p;
	for(int i = 0 ; i < a ; i++){
		tmp = (a-i)*(a-i) + i - parts(b,i+2);
		if(m < tmp){
			m = tmp;
			p = i;
		}
	}

	cout << m << endl;

	long long int x = b/(p+2);
	long long int y = b%(p+2);

	for(int i = 0 ; i < p+2; i ++){
		if(i){
			if(i == p+1)for(int i = 0 ; i < a - p ; i++) cout << "o";
			else cout << "o";
		}
		for(int j = 0 ; j < x ; j++) cout <<"x";
		if(y-- > 0) cout << "x";
	}
	cout << endl;

	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#define fr(i,m,n) for(int i=m; i<=n; i++)
#define dfr(i,m,n) for(int i=m; i>=n;i--)
using namespace std;

typedef long long ll;
const int N=200005;

int c[N];

int a,b;

ll ans;

int main()
{
	cin>>a>>b;
	int f=0;
	if (a==0) {f=1; ans=(ll)-b*b; fr(i,1,b) c[i]=1;}
	if (b==0) {f=1; ans=(ll)a*a; fr(i,1,a) c[i]=2;}
	if (!f && a>=b)
	{
		ans=(ll)-2+(a-b+2)*(a-b+2); printf("%I64d\n", ans);
		printf("x");
		if (b>=2) {fr(i,1,a-b+2) putchar('o'); a-=a-b+2; fr(i,1,a) printf("xo"); putchar('x'); }
		else {fr(i,1,a) putchar('o');}
		return 0;
	}
	if (!f && a<b)
	{
		int split=a+1, sp=b%(a+1), d=b/(a+1);
		ans=(ll)a-(sp*(d+1)*(d+1)+(a+1-sp)*d*d); printf("%I64d\n",ans);
		fr(i,1,sp) {fr(j,1,d+1) printf("x"); printf("o");}
		fr(i,1,a-sp) {fr(j,1,d) printf("x"); printf("o");}
		fr(i,1,d) printf("x");
		return 0;

	}
	printf("%I64d\n", ans);
	fr(i,1,a+b) if (c[i]==2) printf("o"); else printf("x");
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#define fr(i,m,n) for(int i=m; i<=n; i++)
#define dfr(i,m,n) for(int i=m; i>=n;i--)
using namespace std;

typedef long long ll;
const int N=200005;

int a,b;

ll ans;

int main()
{
	scanf("%d%d", &a, &b);
	if (a==0) {printf("%I64d\n", (ll)-b*b); fr(i,1,b) cout<<'x'; return 0;}
	if (b==0) {printf("%I64d\n", (ll)a*a); fr(i,1,a) cout<<'o'; return 0;}
	if (a>=b)
	{
		printf("%I64d\n", (ll)a*a-(b/2)*(b/2)-(b/2+(b&1))*(b/2+(b&1)));
		fr(i,1,b/2+(b&1)) cout<<'x';
		fr(i,1,a) cout<<'o';
		fr(i,1,b/2) cout<<'x';
		return 0;
	}
		int split=a+1, sp=b%(a+1), d=b/(a+1);
		ans=(ll)a-(sp*(d+1)*(d+1)+(a+1-sp)*d*d); printf("%I64d\n",ans);
		fr(i,1,sp) {fr(j,1,d+1) printf("x"); printf("o");}
		fr(i,1,a-sp) {fr(j,1,d) printf("x"); printf("o");}
		fr(i,1,d) printf("x");
		return 0;

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#define fr(i,m,n) for(int i=m; i<=n; i++)
#define dfr(i,m,n) for(int i=m; i>=n;i--)
using namespace std;

typedef long long ll;
const int N=200005;

int a,b;

ll ans;

int main()
{
	scanf("%d%d", &a, &b);
	if (a==0) {printf("%I64d\n", (ll)-b*b); fr(i,1,b) cout<<'x'; return 0;}
	if (b==0) {printf("%I64d\n", (ll)a*a); fr(i,1,a) cout<<'o'; return 0;}
	if (a>=b)
	{
		printf("%I64d\n", (ll)a*a-(b/2)*(b/2)-(b/2+b&1)*(b/2+b&1));
		fr(i,1,b/2+b&1) cout<<'x';
		fr(i,1,a) cout<<'o';
		fr(i,1,b/2) cout<<'x';
		return 0;
	}
		int split=a+1, sp=b%(a+1), d=b/(a+1);
		ans=(ll)a-(sp*(d+1)*(d+1)+(a+1-sp)*d*d); printf("%I64d\n",ans);
		fr(i,1,sp) {fr(j,1,d+1) printf("x"); printf("o");}
		fr(i,1,a-sp) {fr(j,1,d) printf("x"); printf("o");}
		fr(i,1,d) printf("x");
		return 0;

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#define fr(i,m,n) for(int i=m; i<=n; i++)
#define dfr(i,m,n) for(int i=m; i>=n;i--)
using namespace std;

typedef long long ll;
const int N=200005;

ll n,m;

ll calc(ll div)
{
    ll qt=m/div, r=m%div;
    return r*(qt+1)*(qt+1)+(div-r)*qt*qt;
}
// �˺��� ��m<div(����С��0)ʱֵ��m=divʱ��ͬ

int main()
{
    cin>>n>>m;
    if (!n)
    {
        cout<< -m*m <<endl; fr(i,1,m) cout<<'x'; return 0;
    }
    ll ans=-(1LL<<60), tmp, p=0;
    fr(i,0,n-1)
    {
        tmp=(n-i)*(n-i)+i-calc(i+2); // ���ַ������֮ǰ�Ѿ���һ���ϴ�Ĵ���
        if (tmp>ans) ans=tmp, p=i;
    }
    cout<<ans<<endl;
    ll qt=m/(p+2), r=m%(p+2);
    fr(i,0,p+1)
    {
        if (i)
        {
            if (i==1) fr(j,1,n-p) cout<<'o'; else cout<<'o';
        }
        fr(j,1,qt+(i<r)) cout<<'x';
    }
    return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<stdlib.h>
#include<iterator>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<stdio.h>
#include<fstream>
#include<vector>
#include<bitset>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>

using namespace std;

#define all(v)             v.begin(),v.end()
#define sz(v)            ((int)((v).size()))
#define psh(x)                  push_back(x)
#define sc(x)                 scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define lop(i,n)        for(int i=0;i<n;i++)
#define loop(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define INF                       1000000000
#define PI                 3.141592653589793
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<ss, int>     si;
typedef pair<int, ss>     is;
typedef pair<char, int>  chi;
typedef pair<ss, ss>     pss;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<ss>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;

ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return 1; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }

int main()
{
    ll a, b, out = -INF, bp = 0, bq = 0, tp=0, tq=0;
    cin >> a >> b;
    for (ll i = 0; i <= a; ++i)
    {
        for (ll j = i - 1; j < i + 2; j++)
        {
            if (j <= b && (!b || j)&&(!a||i)&&j>=0)
            {
                ll t = (a - i + 1)*(a - i + 1) + (i - 1);
                if (j)t -= (b / j + 1)*(b / j + 1)*(b%j) + (b / j)*(b / j)*(j - (b%j));
                if (t>= out)
                {
                    out = t;
                    bp = i;
                    bq = j;
                }
            }
        }
    }
    printf("%lld\n",out);
    for (int i = 0; i <= max(bp, bq); i++)
    {
        if (tq != bq)
        {
            if (tq < b%bq)lop(i, b / bq + 1)printf("x");
            else lop(i, b / bq)printf("x");
            ++tq;
        }
        if (tp != bp)
        {
            if (tp == 0)lop(i, a - bp + 1)printf("o");
            else printf("o");
            ++tp;
        }
    }

}


#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<stdlib.h>
#include<iterator>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<stdio.h>
#include<fstream>
#include<vector>
#include<bitset>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>

using namespace std;

#define all(v)             v.begin(),v.end()
#define sz(v)            ((int)((v).size()))
#define psh(x)                  push_back(x)
#define sc(x)                 scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define lop(i,n)        for(int i=0;i<n;i++)
#define loop(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define INF                       1000000000
#define PI                 3.141592653589793
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<ss, int>     si;
typedef pair<int, ss>     is;
typedef pair<char, int>  chi;
typedef pair<ss, ss>     pss;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<ss>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;

ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return 1; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }

int main()
{
    ll a, b, out = -(ll(1)<<60), bp = 0, bq = 0, tp=0, tq=0;
    cin >> a >> b;
    for (ll i = 0; i <= a; ++i)
    {
        for (ll j = i - 1; j < i + 2; j++)
        {
            if (j <= b && (!b || j)&&(!a||i)&&j>=0)
            {
                ll t = (a - i + 1)*(a - i + 1) + (i - 1);
                if (j)t -= (b / j + 1)*(b / j + 1)*(b%j) + (b / j)*(b / j)*(j - (b%j));
                if (t>= out)
                {
                    out = t;
                    bp = i;
                    bq = j;
                }
            }
        }
    }
    printf("%lld\n",out);
    for (int i = 0; i <= max(bp, bq); i++)
    {
        if (tq != bq)
        {
            if (tq < b%bq)lop(i, b / bq + 1)printf("x");
            else lop(i, b / bq)printf("x");
            ++tq;
        }
        if (tp != bp)
        {
            if (tp == 0)lop(i, a - bp + 1)printf("o");
            else printf("o");
            ++tp;
        }
    }

}


#include <bits/stdc++.h>

typedef long long LL;
typedef double DB;

#define sf scanf
#define pf printf
#define mp make_pair
#define nl printf("\n")

#define FOR(i,a,b) for(i = a; i <= b; ++i)
#define FORD(i,a,b) for(i = a; i >= b; --i)
#define FORS(i,n) for(i = 0; i < n; ++i)
#define FORM(i,n) for(i = n - 1; i >= 0; --i)
#define reset(i,n) memset(i, n, sizeof(i))

using namespace std;

const LL INF = 4e18;
const int inf = 2e9;

int gcd(int a, int b) { return b? gcd(b, a%b): a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }

LL ans = -INF;

int main(void)
{
    int p = 0, q = 0, a, b, i, j;
    sf("%d %d", &a, &b);
    int n = min(a, b);
    FOR(i, 1, n) {
        LL cur, qq;
        FOR(j, -1, 1) {
            cur = 1LL*(a - i + 1)*(a - i + 1) + i - 1;
            qq = i + j;
            if(qq > b || qq < 1) continue;
            int div = b / qq;
            int mod = b % qq;
            cur -= 1LL*div*div*(qq - mod) + 1LL*(div + 1)*(div + 1)*mod;
            //pf("%I64d %d %d\n", cur, i, qq);
            if(cur > ans) {
                ans = cur;
                p = i;
                q = qq;
            }
        }
    }
    if(!a) q = 1, ans = -1LL*b*b;
    if(!b) p = 1, ans = 1LL*a*a;
    cout << ans << endl;
    int x = (q? b/q : 0);
    int mod = (q? b % q : 0);
    if(q > p) {
        FORS(i, x) pf("x");
        if(mod) {
            pf("x");
            mod--;
        }
    }
    FORS(i, p) {
        if(i) pf("o");
        else
            FORS(j, a - p + 1) pf("o");
        if(i == p - 1 && p > q)
            break;
        if(i < mod)
            FORS(j, x + 1) pf("x");
        else
            FORS(j, x) pf("x");
    }
    nl; return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef double DB;

#define sf scanf
#define pf printf
#define mp make_pair
#define nl printf("\n")

#define FOR(i,a,b) for(i = a; i <= b; ++i)
#define FORD(i,a,b) for(i = a; i >= b; --i)
#define FORS(i,n) for(i = 0; i < n; ++i)
#define FORM(i,n) for(i = n - 1; i >= 0; --i)
#define reset(i,n) memset(i, n, sizeof(i))

using namespace std;

const LL INF = 4e18;
const int inf = 2e9;

int gcd(int a, int b) { return b? gcd(b, a%b): a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }

LL ans = -INF;

int main(void)
{
    int p = 0, q = 0, a, b, i, j;
    sf("%d %d", &a, &b);
    int n = min(a, b);
    FOR(i, 1, n) {
        LL cur, qq;
        FOR(j, -1, 1) {
            cur = 1LL*(a - i + 1)*(a - i + 1) + i - 1;
            qq = i + j;
            if(qq > b || qq < 1) continue;
            int div = b / qq;
            int mod = b % qq;
            cur -= 1LL*div*div*(b - mod) + 1LL*(div + 1)*(div + 1)*mod;
            if(cur > ans) {
                ans = cur;
                p = i;
                q = qq;
            }
        }
    }
    if(!a) q = 1, ans = -1LL*b*b;
    if(!b) p = 1, ans = 1LL*a*a;
    cout << ans << endl;
    int x = (q? b/q : 0);
    int mod = (q? b % q : 0);
    if(q > p) {
        FORS(i, x) pf("x");
        if(mod) {
            pf("x");
            mod--;
        }
    }
    FORS(i, p) {
        if(i) pf("o");
        else
            FORS(j, a - p + 1) pf("o");
        if(i == p - 1 && p > q)
            break;
        if(i < mod)
            FORS(j, x + 1) pf("x");
        else
            FORS(j, x) pf("x");
    }
    nl; return 0;
}


#include<iostream>
using namespace std;
int main()
{
	__int64 a,b;
	cin>>a>>b;
	__int64 ans=0;
	int bn,by;
	int an=1;
	if(a==0)
	{
		ans-=b*b;
		cout<<ans<<endl;
		for(int i=0;i<b;i++)
			cout<<'x';
		cout<<endl;
		return 0;
	}
	else
	{
		__int64 temp=0;
		int i;
		for(i=1;i<=a;i++)
		{
			temp=0;
			temp+=i-1+(a-i+1)*(a-i+1);
			bn=b/(i+1);
			by=b%(i+1);
			temp-=by*(bn+1)*(bn+1)+(i+1-by)*bn*bn;
			if(i==1)
				ans=temp;
			if(temp>ans)
			{
				ans=temp;
				an=i;
			}
		}
	}
	cout<<ans<<endl;
	bn=b/(an+1);
	by=b%(an+1);
	for(int i=0;i<by;i++)
	{
		for(int j=0;j<bn+1;j++)
			cout<<'x';
		cout<<'o';
	}
	for(int i=0;i<an-by;i++)
	{
		for(int j=0;j<bn;j++)
			cout<<'x';
		cout<<'o';
	}
	for(int i=0;i<a-an;i++)
		cout<<'o';
	for(int i=0;i<bn;i++)
		cout<<'x';
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	__int64 ans=0;
	int bn,by;
	int an=1;
	if(a==0)
	{
		ans-=b*b;
		cout<<ans<<endl;
		for(int i=0;i<b;i++)
			cout<<'x';
		cout<<endl;
		return 0;
	}
	else
	{
		__int64 temp=0;
		int i;
		for(i=1;i<=a;i++)
		{
			temp=0;
			temp+=i-1+(a-i+1)*(a-i+1);
			bn=b/(i+1);
			by=b%(i+1);
			temp-=by*(bn+1)*(bn+1)+(i+1-by)*bn*bn;
			if(i==1)
				ans=temp;
			if(temp>ans)
			{
				ans=temp;
				an=i;
			}
		}
	}
	cout<<ans<<endl;
	bn=b/(an+1);
	by=b%(an+1);
	for(int i=0;i<by;i++)
	{
		for(int j=0;j<bn+1;j++)
			cout<<'x';
		cout<<'o';
	}
	for(int i=0;i<an-by;i++)
	{
		for(int j=0;j<bn;j++)
			cout<<'x';
		cout<<'o';
	}
	for(int i=0;i<a-an;i++)
		cout<<'o';
	for(int i=0;i<bn;i++)
		cout<<'x';
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
	ll a,b;
	cin>>a>>b;
	ll ans=0;
	ll bn,by;
	ll an=1;
	if(a==0)
	{
		ans-=b*b;
		cout<<ans<<endl;
		for(ll i=0;i<b;i++)
			cout<<'x';
		cout<<endl;
		return 0;
	}
	else
	{
		ll temp=0;
		ll i;
		for(i=1;i<=a;i++)
		{
			temp=0;
			temp+=i-1+(a-i+1)*(a-i+1);
			bn=b/(i+1);
			by=b%(i+1);
			temp-=by*(bn+1)*(bn+1)+(i+1-by)*bn*bn;
			if(i==1)
				ans=temp;
			if(temp>ans)
			{
				ans=temp;
				an=i;
			}
		}
	}
	cout<<ans<<endl;
	bn=b/(an+1);
	by=b%(an+1);
	for(ll i=0;i<by;i++)
	{
		for(ll j=0;j<bn+1;j++)
			cout<<'x';
		cout<<'o';
	}
	for(ll i=0;i<an-by;i++)
	{
		for(ll j=0;j<bn;j++)
			cout<<'x';
		cout<<'o';
	}
	for(ll i=0;i<a-an;i++)
		cout<<'o';
	for(ll i=0;i<bn;i++)
		cout<<'x';
	cout<<endl;
	return 0;
}


//Author: Vipul Gaur
#include<cstdio>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<iostream>

using namespace std;

long long mx(long long a, long long b){ if(a>b) return a; else return b; }

int main()
{
	long long i,t,n,x=0,sum=0,k,maxt=-10000000000000000,j,a,b, atogether, bside,bnum, brest,snum,rnum,arest;

	cin>>a>>b;

	if(a==0) maxt=-1*b*b;
	if(b==0) maxt=a*a;
	while(a-x >0 && b/(x+2) > 0)
	{
		t=(a-x)*(a-x);
		t-=(((x+2)-(b%(x+2)))*(b/(x+2))*(b/(x+2)));
		t-=((b%(x+2))*((b/(x+2)) + 1)*((b/(x+2)) + 1));
		t+=x;
		if(maxt<t){ maxt=t; atogether=a-x; bside=b/(x+2); brest=bside+1; snum=x+2-(b%(x+2)); rnum=b%(x+2); arest=x; }
		x++;
	}

	cout<<maxt<<endl;
	if(a==0){ while(b--) cout<<"x"; }
	else if(b==0){ while(a--) cout<<"o"; }
	else
	{
		t=bside; bnum=0;
		while(t--)cout<<"x"; snum--; bnum+=bside;
		while(atogether--)cout<<"o"; x=arest;
		while(x--)
		{
			if(snum>0) { t=bside; while(t--)cout<<"x"; snum--; bnum+=bside; }
			else if(rnum>0) { t=brest; while(t--)cout<<"x"; rnum--; bnum+=brest; }

			cout<<"o";
		}
		t=b-bnum;
		while(t--) cout<<"x";
	}

	return 0;
}


//Author: Vipul Gaur
#include<cstdio>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<iostream>

using namespace std;
#define rep(i,a,b) for(i=a;i<b;i++)
#define reps(i,a,b) for(i=a;i>b;i--)

int main()
{
	long long i,j,k,n,t,p,x,o;
	cin>>o>>x;
	if(o==x)
	{
		cout<<"0"<<endl;
		rep(i,0,x) cout<<"ox";
	}
	else if(o < x)
	{
		 cout<<(-1)*(x-o)*(x-o)<<endl;
		 rep(i,0,x-o) cout<<"x";
		 rep(i,0,o) cout<<"ox";
	}
	else
	{
		j=x/2; k=x-j;
		cout<<(o*o)-((j*j) + (k*k))<<endl;
		rep(i,0,j) cout<<"x";
		rep(i,0,o) cout<<"o";
		rep(i,0,k) cout<<"x";
	}

	return 0;
}


//Author: Vipul Gaur
#include<cstdio>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<iostream>

using namespace std;

long long mx(long long a, long long b){ if(a>b) return a; else return b; }

int main()
{
	long long i,t,n,x=0,sum=0,k,maxt=-10000000000000000,j,a,b, atogether, bside,bnum, brest,snum,rnum,arest;

	cin>>a>>b;

	if(a==0) maxt=-1*b*b;
	if(b==0) maxt=a*a;
	while(a-x >0 && b/(x+2) > 0)
	{
		t=(a-x)*(a-x);
		t-=(((x+2)-(b%(x+2)))*(b/(x+2))*(b/(x+2)));
		t-=((b%(x+2))*((b/(x+2)) + 1)*((b/(x+2)) + 1));
		t+=x;
		if(maxt<t){ maxt=t; atogether=a-x; bside=b/(x+2); brest=bside+1; snum=x+2-(b%(x+2)); rnum=b%(x+2); arest=x; }
		x++;
	}

	if(b==1)
	{
		maxt=a*a-1;
	}

	cout<<maxt<<endl;
	if(a==0){ while(b--) cout<<"x"; }
	else if(b==0){ while(a--) cout<<"o"; }
	else if(b==1){ while(a--)cout<<"o"; cout<<"x"; }
	else
	{
		t=bside; bnum=0;
		while(t--)cout<<"x"; snum--; bnum+=bside;
		while(atogether--)cout<<"o"; x=arest;
		while(x--)
		{
			if(snum>0) { t=bside; while(t--)cout<<"x"; snum--; bnum+=bside; }
			else if(rnum>0) { t=brest; while(t--)cout<<"x"; rnum--; bnum+=brest; }

			cout<<"o";
		}
		t=b-bnum;
		while(t--) cout<<"x";
	}

	return 0;
}


//package Div2_165;

import java.util.Scanner;

public class B_Multithreading {

	/**
	 * 2013/02/02
	 * codeforces #165(Div.2)
	 * B.Multithreading
	 * Wrong Answer
	 */
	static Scanner in = new Scanner(System.in);

	public static void run() {
		int n = in.nextInt();
		int out = 0;
		int pre = in.nextInt();
		for(int a=0;a<n-1;a++){
			int back = in.nextInt();
			if(pre > back) out+=a;
		}
		System.out.println(out);
	}
	public static void main(String[] args) {
		B_Multithreading.run();
	}

}


//package Div2_165;

import java.util.Scanner;

public class B_Multithreading {

	/**
	 * @param args
	 */
	static Scanner in = new Scanner(System.in);
	static boolean[] memory;
	public static boolean checkChange(int pre,int back){
		for(int i=pre+1;i<back;i++){
			if(memory[i]) return false;
		}
		return true;
	}

	public static void run() {
		int n = in.nextInt();
		memory = new boolean[n+1];
		int out = 0;
		int pre = in.nextInt();
		n--;
		while(n>0){
			int back = in.nextInt();
			n--;
			if(pre < back){
				if(!checkChange(pre,back)) out++;
			}else{
				out++;
			}
			pre = back;
		}
		System.out.println(out);
	}
	public static void main(String[] args) {
		B_Multithreading.run();
	}

}


//package Div2_165;

import java.util.Scanner;

public class B_Multithreading {

	/**
	 * @param args
	 */
	static Scanner in = new Scanner(System.in);
	static boolean[] memory;
	public static boolean checkChange(int pre,int back){
		for(int i=pre+1;i<back;i++){
			if(!memory[i]) return false;
		}
		return true;
	}

	public static void run() {
		int n = in.nextInt();
		memory = new boolean[n+1];
		int out = 0;
		int pre = in.nextInt();
		n--;
		while(n>0){
			int back = in.nextInt();
			n--;
			if(pre < back){
				if(!checkChange(pre,back)){
					out++;
					memory[pre]=true;
				}
			}else{
				out++;
				memory[pre]=true;
			}
			pre = back;
		}
		System.out.println(out);
	}
	public static void main(String[] args) {
		B_Multithreading.run();
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String... args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int n = Integer.parseInt(s);
int[]t = new int[n];
String[] temp = br.readLine().split(" ");
TreeSet<Integer> set = new TreeSet<Integer>();
for (int i=0; i<n; i++){
  t[i] = Integer.parseInt(temp[i]);
  set.add(t[i]);
}
int min = set.first();
int res = 0;
for (int i=0; i<n; i++){
  set.remove(t[i]);
  if (t[i]>min){
    res++;
  } else if (t[i]==min){
    if (!set.isEmpty()) min = set.first();
  } else {
    throw new IllegalStateException("BAD");
  }
}

System.out.println(res);
}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String... args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int n = Integer.parseInt(s);
int[]t = new int[n];
String[] temp = br.readLine().split(" ");
for (int i=0; i<n; i++) t[i] = Integer.parseInt(temp[i]);
for (int i=n-1; i>0; i--){
  if (t[i]<t[i-1]){
    System.out.println(i);
    System.exit(0);
  }
}
System.out.println(0);
}
}


import java.io.*;
import java.util.*;

public class Multithreading
{
    public static void main(String[] args)throws IOException
    {
        //Scanner input = new Scanner(System.in);
        String a;
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        //a = input.readLine();
        int n = Integer.parseInt(input.readLine());
        int[] num = new int[n];
        a = input.readLine();
        String[] tmp = a.split(" ");
        for(int i=0;i<n;i++)
        {
            //num[i] = input.nextInt();
            num[i] = Integer.parseInt(tmp[i]);
        }
        for(int i=n-1;i>=1;i--)
        {
            if(num[i]<num[i-1])
            {
                System.out.println(i);
                return;
            }
        }
        System.out.println("0");
    }
}


import java.util.*;

public class BMultithreading {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = n - 1; i > 0; i--) {
            if (a[i] > a[i - 1]) {
                ans++;
            } else
                break;
        }
        ans++;
        System.out.println("" + (n - ans));
        return;
    }
}


import java.util.*;

public class BMultithreading {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        boolean wtch = true;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = n - 1; i > 0; i--) {
            if (a[i] > a[i - 1] && wtch) {
                ans++;
            }
            if (a[i] < a[i - 1])
                wtch = false;
        }
        ans++;
        System.out.println("" + (n - ans));
        return;
    }
}


import java.util.*;

public class BMultithreading {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (; n > 0; n--) {
            int k = sc.nextInt();
            if (k == 1)
                break;
            ans++;
        }
        System.out.println(ans);
        return;
    }
}


import java.util.*;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class tmp {
    public static void main(String [] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(in.readLine());
        int out=0, old=Integer.parseInt(st.nextToken()),crn;
        for(int i=1; i<n; i++){
            crn = Integer.parseInt(st.nextToken());
            if(old > crn)
                out++;
            old = crn;
        }
        System.out.println(out);

    }

}

class Pair implements Comparable<Pair>{
    int x,h;

    public Pair(int fi, int ti){
        x = fi;
        h = ti;
    }

    public int compareTo(Pair p){
        return x < p.x ? -1 : (x == p.x ? (h < p.h ? -1 : 1) : 1);
    }
}


import java.util.*;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class tmp {
    public static void main(String [] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(st.nextToken());
        int [] arr = new int[n+1];

        st = new StringTokenizer(in.readLine());
        int out=0;
        for(int i=1; i<=n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }

        for(int i=1; i<n; i++){
            if(arr[i] > arr[i+1])
                out = i;
        }
        System.out.println(out);

    }

}

class Pair implements Comparable<Pair>{
    int x,h;

    public Pair(int fi, int ti){
        x = fi;
        h = ti;
    }

    public int compareTo(Pair p){
        return x < p.x ? -1 : (x == p.x ? (h < p.h ? -1 : 1) : 1);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {
    public static void main(String[] args) throws Exception {
        int n = nextInt();
        int[] positions = new int[n];
        for (int i = 0; i < n; i++) {
            positions[nextInt() - 1] = i;
        }
        int maxPosSoFar = positions[0];
        int res = 0;
        for (int i = 1; i < n; i++) {
            if (positions[i] < maxPosSoFar) {
                res++;
            }
            maxPosSoFar = Math.max(maxPosSoFar, positions[i]);
        }
        System.out.println(res);
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    static String next() throws Exception {
        while (true) {
            if (tokenizer.hasMoreTokens()) {
                return tokenizer.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            tokenizer = new StringTokenizer(s);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {
    public static void main(String[] args) throws Exception {
        int n = nextInt();
        int[] positions = new int[n];
        for (int i = 0; i < n; i++) {
            positions[i] = nextInt();
        }
        int res = 0;
        for (int i = n-2; i>=0; i--) {
            if (positions[i] < positions[i+1]) continue;
                else {
                    res=i+1;
                    break;
                }
        }
        System.out.println(res);
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    static String next() throws Exception {
        while (true) {
            if (tokenizer.hasMoreTokens()) {
                return tokenizer.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            tokenizer = new StringTokenizer(s);
        }
    }
}


import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

/*
 * File: FancyFence.java
 * Created: Feb 1, 2013  9:06:51 PM IST
 * Encoding: UTF-8
 *
 */
/**
 * @author Abhimanyu Singh
 *
 */
public class Multithreading {

    private InputStream in;
    private PrintStream out;
    private Scanner sc;

    public Multithreading(InputStream in, PrintStream out) {
        this.in = in;
        this.out = out;
        init();
    }

    private void init() {
        sc = new Scanner(in);
    }

    static int lineToInt(String line) {
        return Integer.parseInt(line);
    }

    public void solve() {
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int count = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] > min) {
                count++;
            }
            if (min > a[i]) {
                min = a[i];
            }
        }
        out.println(count);
    }

    private void solveTestCase(int testN) {
        int ans = 0;
        out.println(ans);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Multithreading mt = new Multithreading(System.in, System.out);
        mt.solve();
    }
}


import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

/*
 * File: FancyFence.java
 * Created: Feb 1, 2013  9:06:51 PM IST
 * Encoding: UTF-8
 *
 */
/**
 * @author Abhimanyu Singh
 *
 */
public class Multithreading {

    private InputStream in;
    private PrintStream out;
    private Scanner sc;

    public Multithreading(InputStream in, PrintStream out) {
        this.in = in;
        this.out = out;
        init();
    }

    private void init() {
        sc = new Scanner(in);
    }

    static int lineToInt(String line) {
        return Integer.parseInt(line);
    }

    public void solve() {
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int remainig = n;
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] > min) {
                break;
            }
            if (min > a[i]) {
                min = a[i];
            }
            remainig--;
        }
        out.println(remainig);
    }

    private void solveTestCase(int testN) {
        int ans = 0;
        out.println(ans);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Multithreading mt = new Multithreading(System.in, System.out);
        mt.solve();
    }
}


import java.util.*;
public class Multithreading {
    public static void main(String[] Args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] vals = new int[n];
        for(int k =0;k<n;k++)
            vals[k] = sc.nextInt();
        int i;
        for(i=n-2;i>=0&&vals[i]<vals[i+1];i--);
        System.out.println(i+1);
    }
}


import java.util.Scanner;

public class Multithreading {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] arr = new int[in.nextInt()];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = in.nextInt();
		}
		int res = 0;
		int potentiates = 0;
		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] > arr[i + 1]) {
				res++;
				res += potentiates;
				potentiates = 0;
			}
			else if (arr[i] < arr[i + 1]) potentiates++;
		}
		System.out.println(res);
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        final int n=in.readInt();
        int min[]=new int[n];
        int a[]=in.readInts( n );
        min[n-1]=a[n-1];
        for( int i=n-2; i>=0; i-- )
            min[i]=Math.min( a[i], min[i+1] );

        int ans=0;
        for(  int i=0; i<n; i++ ) {
            if( a[i]>min[i] )
                ans++;
        }
        out.printLine( ans );
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public int[] readInts( int n ){
        int ans[]=new int[n];
        for( int i=0; i<n; i++ ) ans[i]=readInt();
        return ans;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        final int n=in.readInt();
        int min[]=new int[n];
        int a[]=in.readInts( n );
        min[n-1]=a[n-1];
        for( int i=n-2; i>=0; i-- )
            min[i]=Math.min( a[i], min[i+1] );

        int ans=0;
        for(  int i=0; i<n; i++ ) {
            if( a[i]>min[i] )
                ans=i+1;
        }
        out.printLine( ans );
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public int[] readInts( int n ){
        int ans[]=new int[n];
        for( int i=0; i<n; i++ ) ans[i]=readInt();
        return ans;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}


//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Codeforces {

    private void run() throws IOException {
        MyScanner sc = new MyScanner(System.in);
        int n = sc.nextInt();
        int min = 1, count = 0;
        boolean[] was = new boolean[n + 1];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a > min) {
                ++count;
            }
            was[a] = true;
            if (a == min) {
                ++min;
                while (min < n && was[min]) {
                    ++min;
                }
            }
        }
        System.out.println(count);
    }

    public static void main(String[] args) throws IOException {
        Codeforces cf = new Codeforces();
        cf.run();
    }
}

class MyScanner {

    private StreamTokenizer st;

    public MyScanner(InputStream is) {
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
    }

    public int nextInt() throws IOException {
        st.nextToken();
        return ((int) st.nval);
    }
}


//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Codeforces {

    private void run() throws IOException {
        MyScanner sc = new MyScanner(System.in);
        int n = sc.nextInt();
        int min = 1, count = 0;
        int susp = 0;
        boolean[] was = new boolean[n + 1];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a > min) {
                count += 1 + susp;
                susp = 0;
            } else {
                ++susp;
            }
            was[a] = true;
            if (a == min) {
                ++min;
                while (min < n && was[min]) {
                    ++min;
                }
            }
        }
        System.out.println(count);
    }

    public static void main(String[] args) throws IOException {
        Codeforces cf = new Codeforces();
        cf.run();
    }
}

class MyScanner {

    private StreamTokenizer st;

    public MyScanner(InputStream is) {
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
    }

    public int nextInt() throws IOException {
        st.nextToken();
        return ((int) st.nval);
    }
}


import java.io.IOException;
import java.util.InputMismatchException;

public class Multithreading {
    public static void main(String[] args) {
        FasterScanner sc = new FasterScanner();

        int N = sc.nextInt();
        int[] A = sc.nextIntArray(N);

        int[] index = new int[N + 1];
        for (int i = 0; i < N; i++) {
        	index[A[i]] = i;
        }

        int cnt = 0;
        int prev = -1;
        for (int i = 1; i <= N; i++) {
        	if (index[i] > prev) {
        		cnt += index[i] - prev - 1;
        		prev = index[i];
        	}
        }
        System.out.println(cnt);
    }

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

	    public int[] nextIntArray(int n) {
	        return nextIntArray(n, 0);
	    }

	    public int[] nextIntArray(int n, int off) {
	    	int[] arr = new int[n + off];
	    	for (int i = 0; i < n; i++) {
	    		arr[i + off] = nextInt();
	    	}
	    	return arr;
	    }

	    public long[] nextLongArray(int n) {
	    	return nextLongArray(n, 0);
	    }

		public long[] nextLongArray(int n, int off) {
		    long[] arr = new long[n + off];
		    for (int i = 0; i < n; i++) {
		        arr[i + off] = nextLong();
		    }
		    return arr;
		}

	    private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}


import java.io.IOException;
import java.util.InputMismatchException;

public class Multithreading {
    public static void main(String[] args) {
        FasterScanner sc = new FasterScanner();

        int N = sc.nextInt();
        int[] A = sc.nextIntArray(N);

        int cnt = 1;
        for (int i = N - 1; i > 0; i--) {
        	if (A[i] > A[i - 1]) {
        		cnt++;
        	} else {
        		break;
        	}
        }
        System.out.println(N - cnt);
    }

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

	    public int[] nextIntArray(int n) {
	        return nextIntArray(n, 0);
	    }

	    public int[] nextIntArray(int n, int off) {
	    	int[] arr = new int[n + off];
	    	for (int i = 0; i < n; i++) {
	    		arr[i + off] = nextInt();
	    	}
	    	return arr;
	    }

	    public long[] nextLongArray(int n) {
	    	return nextLongArray(n, 0);
	    }

		public long[] nextLongArray(int n, int off) {
		    long[] arr = new long[n + off];
		    for (int i = 0; i < n; i++) {
		        arr[i + off] = nextLong();
		    }
		    return arr;
		}

	    private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}


import java.util.*;
public class messages{
    static String test = "5\n5 2 1 3 4\n"+
	"3\n1 2 3\n"+
	"4\n4 3 2 1";
    static String expected = " expected:\n2\n0\n3\n";

    public static void main(String[] args){
	Scanner in = new Scanner(System.in);
	while(in.hasNext()){
	    int hm_threads = Integer.parseInt(in.nextLine());
	    String[] threads = in.nextLine().split(" ");
	    int i=0;
	    for(i=threads.length-1;i>0;i--){
		if(Integer.parseInt(threads[i-1])>Integer.parseInt(threads[i]))break;
	    }
	    System.out.println(i);
	}//while hasnext
	//	System.out.println(expected);//diag
    }
}


import java.util.*;
public class messages{
    static String test = "5\n5 2 1 3 4\n"+
	"3\n1 2 3\n"+
	"4\n4 3 2 1";
    static String expected = " expected:\n2\n0\n3\n";

    public static void main(String[] args){
	Scanner in = new Scanner(System.in);
	while(in.hasNext()){
	    int hm_threads = Integer.parseInt(in.nextLine());
	    String[] threads = in.nextLine().split(" ");
	    int i=0;
	    for(i=threads.length-1;i>0;i--){
		if(Integer.parseInt(threads[i-1])>Integer.parseInt(threads[i]))break;
	    }
	    System.out.println(i);
	}//while hasnext
	System.out.println(expected);//diag
    }
}


import java.util.*;
public class messages{
    public static void main(String[] args){
	Scanner in = new Scanner(System.in);
	while(in.hasNext()){
	    int hm_threads = Integer.parseInt(in.nextLine());
	    String[] threads = in.nextLine().split(" ");
	    int i=0;
	    for(i=threads.length-1;i>0;i--){
		if(Integer.parseInt(threads[i-1])>Integer.parseInt(threads[i]))break;
	    }
	    System.out.println(i);
	}//while hasnext
	System.out.println(expected);//diag
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static int newT = -1;

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numInput = br.readLine();

		String[] tokens = br.readLine().split("\\s+");
		int[] nums = new int[tokens.length];

		for (int i = 0; i < tokens.length; i++) {
			nums[i] = Integer.parseInt(tokens[i]);
		}

		for (int i = 0; i < nums.length; i++) {
			hasSmaller(i, nums);
		}

		if (newT != -1) System.out.println(newT + 1);
		else System.out.println(0);

	}

	public static void hasSmaller(int index, int[] arr) {

		int num = arr[index];

		for (int i = index + 1; i < arr.length; i++) {
			if (num > arr[i]) {
				newT = index;
				break;
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numInput = br.readLine();

		String[] tokens = br.readLine().split("\\s+");
		int[] nums = new int[tokens.length];

		for (int i = 0; i < tokens.length; i++) {
			nums[i] = Integer.parseInt(tokens[i]);
		}

		int newT = 0;

		for (int i = 0; i < nums.length; i++) {
			newT += hasSmaller(i, nums);
		}

		System.out.println(newT);

	}

	public static int hasSmaller(int index, int[] arr) {

		int num = arr[index];

		for (int i = index + 1; i < arr.length; i++) {
			if (num > arr[i]) return 1;
		}
		return 0;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static int newT = 0;

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numInput = br.readLine();

		String[] tokens = br.readLine().split("\\s+");
		int[] nums = new int[tokens.length];

		for (int i = 0; i < tokens.length; i++) {
			nums[i] = Integer.parseInt(tokens[i]);
		}

		for (int i = 0; i < nums.length; i++) {
			hasSmaller(i, nums);
		}

		if (newT != 0) System.out.println(newT + 1);
		else System.out.println(newT);

	}

	public static void hasSmaller(int index, int[] arr) {

		int num = arr[index];

		for (int i = index + 1; i < arr.length; i++) {
			if (num > arr[i]) {
				newT = index;
				break;
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private static int newT = -1;

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numInput = br.readLine();

		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		int[] nums = new int[Integer.parseInt(numInput)];

		int j = 0;
		while (st.hasMoreElements()) {
			nums[j] = Integer.parseInt(st.nextToken());
			j++;
		}

		/*
		String[] tokens = br.readLine().split("\\s+");
		int[] nums = new int[tokens.length];
		*/

		/*
		for (int i = 0; i < tokens.length; i++) {
			nums[i] = Integer.parseInt(tokens[i]);
		}
		*/

		for (int i = 0; i < nums.length; i++) {
			hasSmaller(i, nums);
		}

		if (newT != -1) System.out.println(newT + 1);
		else System.out.println(0);

	}

	public static void hasSmaller(int index, int[] arr) {

		int num = arr[index];

		for (int i = index + 1; i < arr.length; i++) {
			if (num > arr[i]) {
				newT = index;
				break;
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private static int newT = -1;

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numInput = br.readLine();

		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		int[] nums = new int[Integer.parseInt(numInput)];

		int j = 0;
		while (st.hasMoreElements()) {
			nums[j] = Integer.parseInt(st.nextToken());
			j++;
		}

		for (int i = 0; i < nums.length - 1; i++) {

			if (nums[i] > nums[i+1]) {
				newT = i;
			}

		}

		if (newT != -1) System.out.println(newT + 1);
		else System.out.println(0);

	}
}


import java.util.Scanner;

public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        long  counter=0;
        long  x,a=0,b;
        x=in.nextLong();
        if(x!=0)
        a=in.nextLong();
        for(int i=1;i<x; i++)
        {
            b=in.nextLong();
            if(a>b)
                counter=i;
            a=b;
        }
        System.out.println(counter);
    }
}


import java.util.Scanner;
public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        int counter=0;
        int x,a=0,b;
        x=in.nextInt();
		if(x!=0)
        a=in.nextInt();
        for(int i=1;i<x; i++)
        {
            b=in.nextInt();
            if(a>b)
                counter++;
            a=b;
        }
        System.out.println(counter);
    }
}


import java.util.Scanner;
public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        int counter=0;
        int x,a,b;
        x=in.nextInt();
        a=in.nextInt();
        for(int i=1;i<x; i++)
        {
            b=in.nextInt();
            if(a>b)
                counter++;
            a=b;
        }
        System.out.println(counter);
    }
}


import java.util.Scanner;

public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        long  counter=0;
        long  x,a=0,b;
        x=in.nextLong();
        if(x!=0)
        a=in.nextLong();
        for(int i=1;i<x; i++)
        {
            b=in.nextLong();
            if(a>b)
                counter++;
            a=b;
        }
        System.out.println(counter);
    }
}


public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        int counter=0;
        int x,a,b;
        x=in.nextInt();
        a=in.nextInt();
        for(int i=1;i<x; i++)
        {
            b=in.nextInt();
            if(a>b)
                counter++;
            a=b;
        }
        System.out.println(counter);
    }
}


import java.util.Scanner;
public class Pb {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner (System.in);
        int counter=0;
        int x,a,b;
        x=in.nextInt();
		if(x!=0)
        a=in.nextInt();
        for(int i=1;i<x; i++)
        {
            b=in.nextInt();
            if(a>b)
                counter++;
            a=b;
        }
        System.out.println(counter);
    }
}


import java.util.*;
import java.io.*;

public class B {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0;i<n;i++){
			int aa = sc.nextInt();
			a[aa] = i+1;
		}
		int count = 0;
		sc.close();
		for(int i=1;i<n;i++){
			if(a[i]>a[i+1])
				count++;
		}
		out.write(count+"\n");
		out.flush();
	}
}


import java.util.*;
import java.io.*;

public class B {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0;i<n;i++){
			int aa = sc.nextInt();
			a[aa] = i+1;
		}
		ArrayList<Integer> old = new ArrayList<Integer>();
		for(int i=0;i<n+1;i++){
			old.add(a[i]);
		}
		int count = 0;
		for(int i=1;i<n+1;i++){
			//System.out.println(old);
			if(old.get(i)!=i){
				count++;
				old.remove(old.indexOf(i));
				old.add(i, i);
			}

		}
		out.write(count+"\n");
		sc.close();

		out.write("\n");
		out.flush();
	}
}


import java.util.*;
import java.io.*;

public class B {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0;i<n;i++){
			a[i+1] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int count = 0;
		sc.close();
		for(int i=1;i<n+1;i++){
			if(used[i])
				continue;
			int value = -1;
			for(int k=1;k<n+1;k++){
				if(!used[k]){
					value = k;
					break;
				}
			}
			for(int j=i;j<n+1;j++){
				used[a[j]] = true;
				if(a[j]==value){
					i = j;
					break;
				}
				count++;
			}
		}
		out.write(count+"\n");
		out.flush();
	}
}


import java.util.*;
import java.io.*;

public class B {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0;i<n;i++){
			a[i+1] = sc.nextInt();
		}

		int count = 0;
		sc.close();

		int index = -1;
		for(int i=n;i>=1;i--){
			index = i-1;
			if(a[i]>a[i-1]){
				;
			}
			else{
				break;
			}
		}
		count = index;
		out.write(count+"\n");
		out.flush();
	}
}


import java.util.*;
import java.io.*;

public class B {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0;i<n;i++){
			int aa = sc.nextInt();
			a[aa] = i+1;
		}
		ArrayList<Integer> old = new ArrayList<Integer>();
		for(int i=0;i<n+1;i++){
			old.add(a[i]);
		}
		int count = 0;
		for(int i=1;i<n;i++){
			//System.out.println(old);
			if(old.get(i)!=i){
				count++;
				old.remove(old.indexOf(i));
				old.add(i, i);
			}

		}
		out.write(count+"\n");
		sc.close();

		out.write("\n");
		out.flush();
	}
}


import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.BigInteger;

import static java.lang.Math.*;

// Solution is at the bottom of code

public class B implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args){
		new Thread(null, new B(), "", 128 * (1L << 20)).start();
	}

	/////////////////////////////////////////////////////////////////////

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

	////////////////////////////////////////////////////////////////

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	/////////////////////////////////////////////////////////////////////

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	/////////////////////////////////////////////////////////////////////

	String delim = " ";

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}

		return tok.nextToken(delim);
	}

	String readLine() throws IOException{
		return in.readLine();
	}

	/////////////////////////////////////////////////////////////////

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

	/////////////////////////////////////////////////////////////////

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

	///////////////////////////////////////////////////////////////////

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	BigInteger readBigInteger() throws IOException {
		return new BigInteger(readString());
	}

	BigDecimal readBigDecimal() throws IOException {
		return new BigDecimal(readString());
	}

	/////////////////////////////////////////////////////////////////////

	Point readPoint() throws IOException{
		int x = readInt();
		int y = readInt();
		return new Point(x, y);
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		@SuppressWarnings("unchecked")
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

	/////////////////////////////////////////////////////////////////////

	static class IntIndexPair {

		static Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {

			@Override
			public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
				int value1 = indexPair1.value;
				int value2 = indexPair2.value;

				if (value1 != value2) return value1 - value2;

				int index1 = indexPair1.index;
				int index2 = indexPair2.index;

				return index1 - index2;
			}
		};

		static Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {

			@Override
			public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
				int value1 = indexPair1.value;
				int value2 = indexPair2.value;

				if (value1 != value2) return -(value1 - value2);

				int index1 = indexPair1.index;
				int index2 = indexPair2.index;

				return index1 - index2;
			}
		};

		int value, index;

		public IntIndexPair(int value, int index) {
			super();
			this.value = value;
			this.index = index;
		}
	}

	IntIndexPair[] readIntIndexArray(int size) throws IOException {
		IntIndexPair[] array = new IntIndexPair[size];

		for (int index = 0; index < size; ++index) {
			array[index] = new IntIndexPair(readInt(), index);
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	static class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			precision = max(0, precision);
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

	/////////////////////////////////////////////////////////////////////

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	int[][] steps8 = {
			{-1, 0}, {1, 0}, {0, -1}, {0, 1},
			{-1, -1}, {1, 1}, {1, -1}, {-1, 1}
	};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

	/////////////////////////////////////////////////////////////////////

	boolean checkBit(int mask, int bitNumber){
		return (mask & (1 << bitNumber)) != 0;
	}

	/////////////////////////////////////////////////////////////////////

	void solve() throws IOException {
		int n = readInt();
		int[] array = readIntArray(n);

		int answer = getCount(n, array);
		out.println(answer);
	}

	private int getCount(int n, int[] array) {
		for (int i = n - 1; i > 0; --i) {
			if (array[i] < array[i-1]) {
				return i;
			}
		}

		return 0;
	}
}


import java.util.Scanner;

public class B {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[s.nextInt() - 1] = i + 1;
        }
        int lastA = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            int ai = a[i];
            if (ai > lastA) {
                if (ai > lastA + 1) {
                    count = ai - 1;
                }
                lastA = ai;
            }
        }
        System.out.println(count);
    }
}


import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int last = -1;
        int count = 0;
        for (int i = 0; i < n; i++) {
            int a = s.nextInt();
            if (a < last) {
                count = 1;
            } else {
                count++;
            }
            last = a;
        }
        System.out.println(n - count);
    }
}


import java.util.Scanner;

public class Main2 {

    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i < n ; i++){
        	a[i] = input.nextInt();
        }
        int index = 0;
        int num = -1;
        boolean flag = false;
        for(int i = a.length-1 ; i >= 0 ; i--){
        	if(num == -1){
        		num = a[i];
        	}else{
        		if(a[i] < num){
        			num = a[i];
        		}else{
        			index = i;
        			flag = true;
        			break;
        		}
        	}
        }
        if(flag){
        	System.out.println(index+1);
        }else{
        	System.out.println(0);
        }
    }
}


import java.util.Scanner;

public class Main2 {

    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i < n ; i++){
        	a[i] = input.nextInt();
        }
        int count = 0;
        for(int i = 0 ; i < a.length ; i++){
        	if(a[i] == 1)break;
        	count++;
        }
        System.out.println(count);
    }
}


import java.util.Scanner;

public class Threading {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
    }
    int[] mins = new int[n];
    mins[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      mins[i] = Math.min(mins[i + 1], a[i]);
    }
    int t = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > mins[i]) {
        t++;
      }
    }
    System.out.println(t);
  }
}


import java.util.Scanner;

public class Threading {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
    }
    int[] mins = new int[n];
    mins[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      mins[i] = Math.min(mins[i + 1], a[i]);
    }
    int t = -1;
    for (int i = 0; i < n; i++) {
      if (a[i] > mins[i]) {
        t = i;
      }
    }
    System.out.println(t + 1);
  }
}


import java.util.Scanner;

public class Threading {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
    }
    int[] mins = new int[n];
    mins[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      mins[i] = Math.min(mins[i + 1], a[i]);
    }
    int t = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > mins[i]) {
        t = i;
      }
    }
    System.out.println(t + 1);
  }
}


import java.util.Scanner;

public class P270B_Multithreading {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		// read the inputs
		int n = scanner.nextInt();
		int[] threads = new int[n];

		for (int i = 0; i < n; i++) {
			threads[i] = scanner.nextInt();
		}

		scanner.close();

		int i = n - 1;

		while (i > 0 && threads[i] > threads[i - 1]) {
			i--;
		}

		System.out.println(i);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Multithreading {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n=Integer.parseInt(br.readLine());
			String order[]=br.readLine().split(" ");
			for(int i=0;i<n;i++){
				if("1".equalsIgnoreCase(order[i])){
					System.out.println(i);
					break;
				}
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.omg.CORBA.IntHolder;

public class Multithreading {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			String order[] = br.readLine().split(" ");
			int i = n - 1;
			boolean flag=false;
			for (; i > 0; i--) {
				if (Integer.parseInt(order[i]) < Integer.parseInt(order[i - 1])) {
					System.out.println(i);
					flag=true;
					break;
				}
			}
			if(!flag){
				System.out.println(i);
			}

		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    int[] aib;
    int N;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        N = in.nextInt();
        aib = new int[N + 1];
        int[] A = new int[N];

        for(int i = 0; i < N; i++)
            A[i] = in.nextInt();

        int ans = 0;
        for(int i = N - 1; i >= 0; i--) {
            if(query(A[i]) > 0)
                ans++;
            update(A[i]);
        }

        out.println(ans);
    }

    private void update(int pos) {
        while(pos <= N) {
            aib[pos]++;
            pos += (pos & (-pos));
        }
    }

    private int query(int pos) {
        while(pos > 0) {
            if(aib[pos] > 0)
                return 1;
            pos -= (pos & (-pos));
        }
        return 0;
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    int[] aib;
    int N;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        N = in.nextInt();
        aib = new int[N + 1];
        int[] A = new int[N];

        for(int i = 0; i < N; i++)
            A[i] = in.nextInt();

        int ans = 0;
        for(int i = N - 1; i >= 0; i--) {
            if(query(A[i]) > 0) {
                ans = i + 1;
                break;
            }
            update(A[i]);
        }

        out.println(ans);
    }

    private void update(int pos) {
        while(pos <= N) {
            aib[pos]++;
            pos += (pos & (-pos));
        }
    }

    private int query(int pos) {
        while(pos > 0) {
            if(aib[pos] > 0)
                return 1;
            pos -= (pos & (-pos));
        }
        return 0;
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


import java.util.Scanner;

/**
 * @author artyom
 */
public class Multithreading {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int i = n - 1;
        while (i > 0 && a[i] > a[i - 1]) {
            i--;
        }
        System.out.println(i);
    }
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

    public void solve() throws IOException {
        StringBuffer sb = new StringBuffer("");
        int N = nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = nextInt();
        }
        int cnt = 0;
        for (int i = 1; i < N; i++) {
            if (a[i - 1] > a[i]) {
                cnt++;
            }
            if (a[i] == 1) {
                break;
            }
        }
        if (a[0] == 1) {
            cnt = 0;
        }
        sb.append(cnt).append("\n");
        System.out.print(sb);
    }

    void print(Object... obj) {
        for (Object o : obj) {
            System.out.println(o);
        }
    }

    void print(int[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }

    void print(int[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    void print(boolean[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    //-----------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    public String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    BufferedReader in;
    StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

    public void solve() throws IOException {
        StringBuffer sb = new StringBuffer("");
        int N = nextInt();
        int[] a = new int[N];
        int find = -1;
        int lind = -1;
        boolean inorder = true;
        for (int i = 0; i < N; i++) {
            a[i] = nextInt();
        }
        int i = N - 2;
        for (; i >= 0; i--) {
            if (a[i + 1] < a[i]) {
                break;
            }
        }
        sb.append(i + 1).append("\n");
        System.out.print(sb);
    }

    void print(Object... obj) {
        for (Object o : obj) {
            System.out.println(o);
        }
    }

    void print(int[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }

    void print(int[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    void print(boolean[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    //-----------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    public String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    BufferedReader in;
    StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

    public void solve() throws IOException {
        StringBuffer sb = new StringBuffer("");
        int N = nextInt();
        int[] a = new int[N];
        int find = -1;
        int lind = -1;
        boolean inorder = true;
        for (int i = 0; i < N; i++) {
            a[i] = nextInt();
            if (a[i] != i + 1) {
                inorder = false;
            }
            if (a[i] == 1) {
                find = i;
            }
            if (a[i] == N) {
                lind = i;
            }
        }
        if (inorder) {
            sb.append(0);
        } else {
            int val = Math.abs(find - lind);
            if (find < lind) {
                val += 1;
            }
            sb.append(val);
        }
        sb.append("\n");
        System.out.print(sb);
    }

    void print(Object... obj) {
        for (Object o : obj) {
            System.out.println(o);
        }
    }

    void print(int[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }

    void print(int[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    void print(boolean[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    //-----------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    public String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    BufferedReader in;
    StringTokenizer tok;
}


import java.util.Scanner;
import java.util.Stack;

public class DiscussionsSolverSolver {

    private int n;

    private int[] a;

    public static void main(String[] args) {
        DiscussionsSolverSolver solver = new DiscussionsSolverSolver();

        solver.readData();
        int solution = solver.solve();
        System.out.println(String.format("%d", solution));
    }

    private void readData() {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();

        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
    }

    private int solve() {
        int result = 0;

        int[] indices = calculateGreaterRightIndices();

        for (int i = 0; i < indices.length; i++) {
            if (indices[i] < n) {
                result++;
            }
        }

        return result;
    }

    private int[] calculateGreaterRightIndices() {
        // for each a[i] calculates index c[i] - the lowest index c[i] > i such that a[c[i]] < a[i]
        // a[j] >= a[i] for each i < j < c[i].
        Stack<Integer> stack = new Stack<Integer>();
        int[] c = new int[n];

        stack.push(n);
        for (int i = n - 1; i >= 0; i--) {
            while (stack.peek() != n && a[stack.peek()] >= a[i]) {
                stack.pop();
            }
            c[i] = stack.peek();
            stack.push(i);
        }

        return c;
    }
}


import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;

public class DiscussionsSolverSolver {

    private int n;

    private int[] a;

//    private Set<Integer> moved = new TreeSet<Integer>();

    public static void main(String[] args) {
        DiscussionsSolverSolver solver = new DiscussionsSolverSolver();

        solver.readData();
        int solution = solver.solve();
        System.out.println(String.format("%d", solution));
    }

    private void readData() {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();

        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
    }

    private int solve() {

        int[] now = new int[n];

        for (int i = 0; i < a.length; i++) {
            now[a[i] - 1] = i;
        }

        boolean[] moved = new boolean[n];
        int movedCount = 0;

        for (int i = now.length - 1; i >= 0; i--) {
            if (now[i] < i + movedCount) {
                moved[i] = true;
                movedCount++;
            }
        }

        int result = 0;

        for (int i = 0; i < moved.length; i++) {
            if (moved[i]) {
                result++;
            }
        }

        return result;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class CF165B implements Runnable {

    Locale L = Locale.US;
    StringTokenizer tokenizer;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) {
        new Thread(new CF165B()).start();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } catch (Exception e) {
            System.exit(9000);
        } finally {
            out.flush();
            out.close();
        }
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(in.readLine());
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    String nextString() throws IOException {
        return nextToken();
    }

    void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }

        int c = 0;
        int s = 0;
        for (int i = 0; i < n - 1; i++) {
            if (a[i + 1] > a[i]) {
               s += 1;
            } else {
                c += s + 1;
                s = 0;
            }
        }

        out.println(c);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class CF165B implements Runnable {

    Locale L = Locale.US;
    StringTokenizer tokenizer;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) {
        new Thread(new CF165B()).start();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } catch (Exception e) {
            System.exit(9000);
        } finally {
            out.flush();
            out.close();
        }
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(in.readLine());
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    String nextString() throws IOException {
        return nextToken();
    }

    void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }

        int c = 0;
        int offset = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != i - offset + 1) {
                c += 1;
                offset += 1;
            } else {
                break;
            }
        }

        out.println(c);
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan= new Scanner(System.in);
		int init= scan.nextInt();

		int aux=scan.nextInt();
		int count=0;
		for (int i = 0; i < init-1; i++) {
			int aux2=scan.nextInt();
			if(aux2<aux){
				count=i+1;
			}
			aux=aux2;
		}

	System.out.println(count);
	}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan= new Scanner(System.in);
		int init= scan.nextInt();

		int aux=scan.nextInt();
		int count=0;
		for (int i = 0; i < init-1; i++) {
			int aux2=scan.nextInt();
			if(aux2<aux){
				count=i+1;
			}
			aux=aux2;
		}

	System.out.println(count);
	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan= new Scanner(System.in);
		int init= scan.nextInt();

		int aux=scan.nextInt();
		int count=0;
		for (int i = 0; i < init-1; i++) {
			int aux2=scan.nextInt();
			if(aux2<aux){
				count++;
			}
			aux=aux2;
		}

	System.out.println(count);
	}

}


import java.util.ArrayList;
import java.util.Scanner;
public class Problem270B
{
	public static void main(String args[])
	{
		Scanner scanner = new Scanner(System.in);
		int looptime = scanner.nextInt();
		int answer = looptime-1;
		ArrayList<Integer> numbers = new ArrayList<>();
		for(int i = 0;i<looptime;i++)
		{
			numbers.add(scanner.nextInt());
		}
		scanner.close();

        for (int i = looptime - 1; i > 0; i--) {
            if (numbers.get(i) < numbers.get(i - 1)) {
                break;
            }
            answer--;
        }
		System.out.println(answer);
	}
}