#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second
#define PI 2*acos(0)

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

void arquivo()
{
	freopen("","r",stdin);
	freopen("","w",stdout);
}

const int N = 100001;

ll v[N];
int n;
int tr[4*N];

int join( int a, int b ){
	if( a == -1 ) return b;
	if( b == -1 ) return a;
	if( v[a] <= v[b] ) return a;
	else return b;
}

void build( int no, int l, int r ){
	if( l == r ){
		tr[no] = l;
		return;
	}
	int nxt = (no<<1), mid = (l+r)>>1;
	build(nxt,l,mid); build(nxt+1,mid+1,r);
	tr[no] = join(tr[nxt],tr[nxt+1]);
}

int query( int no, int l, int r, int i, int j ){
	if( r < i || l > j ) return -1;
	if( l >= i && r <= j ) return tr[no];
	int nxt = (no<<1), mid = (l+r)>>1;
	return join(query(nxt,l,mid,i,j),query(nxt+1,mid+1,r,i,j));
}

int main()
{
	//ios::sync_with_stdio(0);
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%lld",v+i);
	}
	build(1,0,n-1);

	int pos = 0;
	ll qtd = 0;
	while( pos != n ){
		qtd++;
		pos = query(1,0,n-1,pos,n-1)+1;
	}
	printf("%lld\n",qtd);

	return 0;
}


#include <iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>

using namespace std;

long a[100005];
long n,cnt=0;
map<pair<long,long > ,long >mp;
long rec(long pos,long lmx)
{
    if(pos==n-1)
        {cnt++;return a[pos];}
    if(a[pos]>lmx)
        {lmx=a[pos];}//cout<<"dg\n";}
    pair<long,long> p;
    p=make_pair(pos,lmx);
    if(mp[p]!=0)
        return mp[p];
    long x;
    /*if(a[pos+1]<lmx)
    {
        x=rec(pos+1,lmx);
    }
    else if(a[pos+1]==lmx)
    {*/
        x=rec(pos+1,lmx);
        if(x>=lmx)
            cnt++;
    /*}
    else
    {
        x=rec(pos+1,lmx);
        cnt++;
    }*/
    if(a[pos]<x)
        x=a[pos];
    //cout<<pos<<" "<<x<<" "<<lmx<<endl;
    mp[p]=x;
    return x;
}
int main()
{

    scanf("%ld",&n);
    for(long i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    long x=rec(0,0);
    printf("%ld\n",cnt);
    return 0;
}


#include <iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>

using namespace std;

long a[100005];
long n;
map<pair<long,long > ,long >mp;
long rec(long pos,long lmx)
{
    if(pos==n-1)
        return 1;
    if(a[pos]>lmx)
        {lmx=a[pos];}//cout<<"dg\n";}
    /*pair<long,long> p;
    p=make_pair(pos,lmx);
    if(mp[p]!=0)
        return mp[p];*/
    long x;
    if(a[pos+1]<lmx)
    {
        x=rec(pos+1,lmx);
    }
    else
    {
        long x1=rec(pos+1,lmx);
        long x2=rec(pos+1,lmx)+1;
        x=max(x1,x2);
    }
    //mp[p]=x;
    return x;
}
int main()
{

    scanf("%ld",&n);
    for(long i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    long x=rec(0,0);
    printf("%ld\n",x);
    return 0;
}


#include <iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>

using namespace std;

long a[100005];
long n;
map<pair<long,long > ,long >mp;
long rec(long pos,long lmx)
{
    if(pos==n-1)
        return 1;
    if(a[pos]>lmx)
        {lmx=a[pos];}//cout<<"dg\n";}
    pair<long,long> p;
    p=make_pair(pos,lmx);
    if(mp[p]!=0)
        return mp[p];
    long x;
    if(a[pos+1]<lmx)
    {
        x=rec(pos+1,lmx);
    }
    else
    {
        long x1=rec(pos+1,lmx);
        long x2=rec(pos+1,lmx)+1;
        x=max(x1,x2);
    }
    mp[p]=x;
    return x;
}
int main()
{

    scanf("%ld",&n);
    for(long i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    long x=rec(0,0);
    printf("%ld\n",x);
    return 0;
}


#include <iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>

using namespace std;

long a[100005];
long n;
map<pair<long,long > ,long >mp;
long rec(long pos,long lmx)
{
    if(pos==n-1)
        return 1;
    if(a[pos]>lmx)
        {lmx=a[pos];}//cout<<"dg\n";}
    pair<long,long> p;
    p=make_pair(pos,lmx);
    if(mp[p]!=0)
        return mp[p];
    long x;
    if(a[pos+1]<=lmx)
    {
        x=rec(pos+1,lmx);
    }
    else
    {
        long x1=rec(pos+1,lmx);
        long x2=rec(pos+1,lmx)+1;
        x=max(x1,x2);
    }
    //cout<<pos<<" "<<x<<" "<<lmx<<endl;
    mp[p]=x;
    return x;
}
int main()
{

    scanf("%ld",&n);
    for(long i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    long x=rec(0,0);
    printf("%ld\n",x);
    return 0;
}


#include <iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>

using namespace std;

long a[100005];
long n,cnt=0;
map<pair<long,long > ,long >mp;
long rec(long pos,long lmx)
{
    if(pos==n-1)
        {cnt++;return a[pos];}
    if(a[pos]>lmx)
        {lmx=a[pos];}//cout<<"dg\n";}
    pair<long,long> p;
    p=make_pair(pos,lmx);
    if(mp[p]!=0)
        return mp[p];
    long x;
    if(a[pos+1]<lmx)
    {
        x=rec(pos+1,lmx);
    }
    else if(a[pos+1]==lmx)
    {
        x=rec(pos+1,lmx);
        if(x>=lmx)
            cnt++;
    }
    else
    {
        //long x1=rec(pos+1,lmx);
        x=rec(pos+1,lmx);
        cnt++;
        //x=max(x1,x2);
    }
    if(a[pos]<x)
        x=a[pos];
    //cout<<pos<<" "<<x<<" "<<lmx<<endl;
    mp[p]=x;
    return x;
}
int main()
{

    scanf("%ld",&n);
    for(long i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    long x=rec(0,0);
    printf("%ld\n",cnt);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
    if(imin==-1||imax==-1||imax==imin)
        return 1;

    if(imin>=imax){
        if(imax==i1+1)
            return 1;
        for(i=imax-1;i>i1;i--){
            if(v[i]>v[imin])
                return 1;
        }
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 1;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }

    return 2+make(imin,imax);
}
int main(){
    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<minim<<" "<<maxim<<"\n";
    if(imin==-1||imax==-1||imax==imin)
        return 1;

    if(imin>=imax){

        if(v[i1+1]==minim)
            return 1+make(i1+1,i2);
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 0;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }
    return 2+make(imin,imax);
}
int main(){

    f>>N;
    for(i=0;i<N;i++){
        f>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int N,v[101010],v2[101010],i,sum1,sum2,rasp;
int main(){
    cin>>N;
    for(i=1;i<=N;i++){
        cin>>v[i];
        v2[i]=v[i];
    }
    sort(v+1,v+1+N);
    for(i=1;i<=N;i++){
        sum1+=v[i];
        sum2+=v2[i];
        if(sum1==sum2)
            rasp++;
    }
    cout<<rasp;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=2,imax=1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
    if(imin>=imax)
        return 1;
    else{
        minp=maxim;
        for(i=imax+1;i<i2;i++)
            if(v[i]<minp)
                minp=v[i];
        for(i=i1+1;i<imax;i++)
            if(v[i]>minp){
                imax=i;
            }
        if(imax==i1+1)
            return 1;
        minimt=1000000001;
        for(i=i1+1;i<imax;i++)
            if(v[i]<minimt){
                minimt=v[i];
                imin=i;
            }

        return 2+make(imin,imax);
    }

}
int main(){
    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<minim<<" "<<maxim<<"\n";
    if(imin==-1||imax==-1||imax==imin)
        return 1;

    if(imin>=imax){

        if(v[i1+1]==minim)
            return 1+make(i1+1,i2);
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 0;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k;
int i;
int make(int i1,int i2){
    long long maxim=-1,minim=1000000001,imax=-1,imin=-1;
    if(i2<=i1) return -1;
    for(i=i1+1;i<i2;i++){
        if(maxim<v[i]){
            maxim=v[i];
            imax=i;
        }
        if(minim>=v[i]){
            minim=v[i];
            imin=i;
        }
    }
    if(imax==-1&&imin==-1)
        return 0;
    else if(imax==-1)
        imax=i2;
    else if(imin==-1)
        imin=i1;
    //cout<<imax<<imin;
    return 2+make(imin,imax);

}
int main(){
    cin>>N;
    for(i=1;i<=N;i++){
        cin>>v[i];
        minim=min(v[i],minim);
        maxim=max(v[i],maxim);
    }
    ok=1;
    for(i=1;i<=N;i++){
        if(v[i]==minim)
            j=i;
    }
    for(i=1;i<=N&&ok;i++){
        if(v[i]==maxim){
            k=i;
            ok=0;
        }
    }
    if(k>j)
        cout<<2+make(j,k);
    else cout<<1;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return -1;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<minim<<" "<<maxim<<"\n";
    if(imin==-1||imax==-1||imax==imin)
        return 1;

    if(imin>=imax){

        if(v[i1+1]==minim)
            return 1+make(i1+1,i2);
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 0;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp,imaxi;
int i;
int make(int i1,int i2){
    //cout<<i1<<": "<<v[i1+1]<<" "<<i2<<": "<<v[i2-1]<<endl;
    if(i2<=i1+1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<i1<<"!!!"<<imin<<": "<<minim<<" "<<imax<<": "<<maxim<<"\n";
    if(imax==imin)
        return 1;
    if(v[i1+1]==minim)
        return 1+make(i1+1,i2);
    if(v[i2-1]==maxim)
        return 1+make(i1,i2-1);
    if(imin>=imax){
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 1;
    maxp=minim;
    imaxi=-1;
    for(i=imin-1;i>i1;i--)
        if(v[i]>maxp)
            maxp=v[i];
    for(i=i2-1;i>imin;i--)
        if(v[i]<maxp){
            maxp=v[i];
            imin=i;
        }
    if(imax<=imin)
        return 1;
    if(imax==imin+1)
        return 1;
    //cout<<" apelare: imin: "<<imin<<" ; imax: "<<imax<<endl;
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
  // cout<<minim<<" "<<maxim<<"\n";
    if(imin==-1||imax==-1||imax==imin)
        return 1;
    if(v[i1+1]==minim)
        return 1+make(i1+1,i2);
    if(imax==imin+1)
        return 2;
    if(imin>=imax){

        if(v[i1+1]==minim)
            return 1+make(i1+1,i2);
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 0;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp,imaxi;
int i;
int make(int i1,int i2){
    //cout<<i1<<": "<<v[i1+1]<<" "<<i2<<": "<<v[i2-1]<<endl;
    if(i2<=i1+1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<i1<<"!!!"<<imin<<": "<<minim<<" "<<imax<<": "<<maxim<<"\n";
    if(imax==imin)
        return 1;
    if(v[i1+1]==minim)
        return 1+make(i1+1,i2);
    if(v[i2-1]==maxim)
        return 1+make(i1,i2-1);
    if(imin>=imax){
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 1;
    maxp=minim;
    imaxi=-1;
    for(i=imin-1;i>i1;i--)
        if(v[i]>maxp)
            maxp=v[i];
    for(i=i2-1;i>imin;i--)
        if(v[i]<maxp){
            maxp=v[i];
            imin=i;
        }
    if(imax<=imin)
        return 1;
    if(imax==imin+1)
        return 2;
    //cout<<" apelare: imin: "<<imin<<" ; imax: "<<imax<<endl;
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 1;
    int i,maxim=-1,minim=1000000001,j,k,imin=2,imax=1;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
    if(imin>imax)
        return 0;
    if(imin==imax)
        return 1;
    else{
        minp=maxim;
        for(i=imax+1;i<i2;i++)
            if(v[i]<minp)
                minp=v[i];
        for(i=i1+1;i<imax;i++)
            if(v[i]>minp){
                imax=i;
            }
        return 2+make(imin,imax);
    }

}
int main(){
    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp,imaxi;
int i;
int make(int i1,int i2){
    //cout<<i1<<": "<<v[i1+1]<<" "<<i2<<": "<<v[i2-1]<<endl;
    if(i2<=i1+1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<i1<<"!!!"<<imin<<": "<<minim<<" "<<imax<<": "<<maxim<<"\n";
    if(imax==imin)
        return 1;
    if(v[i1+1]==minim)
        return 1+make(i1+1,i2);
    if(v[i2-1]==maxim)
        return 1+make(i1,i2-1);
    if(imin>=imax){
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 1;
    maxp=minim;
    imaxi=-1;
    for(i=imin-1;i>i1;i--)
        if(v[i]>maxp)
            maxp=v[i];
    for(i=i2-1;i>imin;i--)
        if(v[i]<maxp){
            imin=i;
        }
    if(imax<=imin)
        return 1;
    //cout<<" apelare: imin: "<<imin<<" ; imax: "<<imax<<endl;
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
//ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp,imaxi;
int i;
int make(int i1,int i2){
    //cout<<i1<<": "<<v[i1+1]<<" "<<i2<<": "<<v[i2-1]<<endl;
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
   //cout<<i1<<"!!!"<<imin<<": "<<minim<<" "<<imax<<": "<<maxim<<"\n";
    if(imax==imin)
        return 1;
    if(v[i1+1]==minim)
        return 1+make(i1+1,i2);
    if(v[i2-1]==maxim)
        return 1+make(i1,i2-1);
    if(imin>=imax){
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 1;
    maxp=minim;
    imaxi=-1;
    for(i=imin-1;i>i1;i--)
        if(v[i]>maxp)
            maxp=v[i];
    for(i=i2-1;i>imin;i--)
        if(v[i]<maxp){
            maxp=v[i];
            imin=i;
        }
    if(imax<=imin)
        return 1;
    minimt=1000000001;
    //cout<<" apelare: imin: "<<imin<<" ; imax: "<<imax<<endl;
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
ifstream f("date.in");
long long N,v[101010],maxim=-1,minim=1000000001,ok,j,k,minp,maxp,imaxp,iminp;
int i;
int make(int i1,int i2){
    if(i2==i1+1)
        return 0;
    if(i2<i1)
        return 0;
    if(i2==i1)
        return 0;
    int i,maxim=-1,minim=1000000001,j,k,imin=-1,imax=-1,minimt;
    for(i=i1+1;i<i2;i++){
        if(v[i]<=minim){
            minim=v[i];
            imin=i;
        }
        if(v[i]>maxim){
            maxim=v[i];
            imax=i;
        }
    }
  // cout<<minim<<" "<<maxim<<"\n";
    if(imin==-1||imax==-1||imax==imin)
        return 1;
    if(imax==imin+1)
        return 2;
    if(imin>=imax){

        if(v[i1+1]==minim)
            return 1+make(i1+1,i2);
        return 1;
    }

    minp=maxim;
    for(i=imax+1;i<i2;i++)
        if(v[i]<minp)
            minp=v[i];
    for(i=i1+1;i<imax;i++)
        if(v[i]>minp){
            imax=i;
        }
    if(imax==i1+1)
        return 0;
    minimt=1000000001;
    for(i=i1+1;i<imax;i++)
        if(v[i]<minimt){
            minimt=v[i];
            imin=i;
        }
    return 2+make(imin,imax);
}
int main(){

    cin>>N;
    for(i=0;i<N;i++){
        cin>>v[i];
    }
    cout<<make(-1,N);
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
int a[100005];
int min1[100005];
int max1[100005];
using namespace std;
int main(void)
{
    int n,i,j,k,p,q;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    max1[0]=a[0];
    min1[n-1]=a[n-1];
    for(i=1; i<n; i++)
    {
        if(a[i]<max1[i-1])
        {
            max1[i]=max1[i-1];
        }
        else max1[i]=a[i];

    }
    for(i=n-2; i>=0; i--)
    {
        if(a[i]>min1[i+1])
        {
            min1[i]=min1[i+1];
        }
        else min1[i]=a[i];

    }
    int sum=1;
    for(i=0; i<n-1; i++)
    {
        if(max1[i]<=min1[i+1])
        {
            sum++;
        }
    }

    printf("%d\n",sum);
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
int a[100005];
int main(void)
{int i,j,k,p,q,n;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int d=a[1];int cnt=0;
        for(i=1;i<=n;i++)
        {
            if(d<=a[i])
            {
                d=a[i];
                cnt++;
            }
            else if(d>a[i])
            {
                d=a[i];
            }
        }
        printf("%d\n",cnt);
    }
return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
int a[100005];
int main(void)
{int i,j,k,p,q,n;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int d=a[1];int cnt=0;
        for(i=1;i<=n;i++)
        {
            if(d<=a[i])
            {
                d=a[i];
                cnt++;
            }

        }
        printf("%d\n",cnt);
    }

return 0;

}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
int a[100005];
int b[100005];
int main(void)
{int i,j,k,p,q,n;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
       sort(b+1,b+n+1);
       int fi=1;int cnt=0;
       for(i=1;i<=n;i++)
       {
           if(a[fi]==b[i])
           {
               fi=i+1;
               cnt++;if(fi>n)
               {
                   break;
               }

           }
       }
        printf("%d\n",cnt);
    }
return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
int a[100005];
int min1[100005];
int max1[100005];
using namespace std;
int main(void)
{
    int n,i,j,k,p,q;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    max1[0]=a[0];
    min1[n-1]=a[n-1];
    for(i=1; i<n; i++)
    {
        if(a[i]<max1[i-1])
        {
            max1[i]=max1[i-1];
        }
        else max1[i]=a[i];

    }
    for(i=n-2; i>=0; i--)
    {
        if(a[i]>min1[i+1])
        {
            min1[i]=min1[i+1];
        }
        else min1[i]=a[i];

    }
    int sum=0;
    for(i=0; i<n-1; i++)
    {
        if(max1[i]<=min1[i+1])
        {
            sum++;
        }
    }

    printf("%d\n",sum);
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int t[100010];
int a[100010],h[100010];

void upd(int x)
{
    while(x<100010)
    {
        t[x]++;
        x+=(x&-x);
    }
}

int get(int x)
{
    int ret=0;
    while(x)
    {
        ret+=t[x];
        x-=(x&-x);
    }
    return ret;
}

int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
    {
        cin>>h[i];
        a[i]=h[i];
    }
    int ans=n;
    sort(a,a+n);
    fi(i,0,n)
        h[i]=(int)(lower_bound(a,a+n,h[i])-a)+1;
    fd(i,n-1,0)
    {
        ans-=get(h[i]-1);
        upd(h[i]);
    }
    ans=max(ans,1);
    cout<<ans<<endl;
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int a[100010],h[100010];
int last[100010],dp[100010];
int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
    {
        cin>>h[i];
        a[i]=h[i];
    }
    sort(a,a+n);
    fi(i,0,n)
        h[i]=(int)(lower_bound(a,a+n,h[i])-a)+1;
    fi(i,1,n+1)
        last[i]=-1;
    fd(i,n-1,0)
        if(last[h[i]]==-1)
            last[h[i]]=i;
    dp[1]=-1;
    dp[2]=last[1];
    fi(i,3,n+1)
        dp[i]=max(dp[i-1],last[i-1]);
    int i=0,ans=0;
    while(i<n)
    {
        if(h[i]==1)
        {
            ans++;
            i++;
            continue;
        }
        int idx=dp[h[i]];
        if(idx<=i)
        {
            ans++;
            i++;
            continue;
        }
        i=idx+1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int h[100010];
int dp[100010];
int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
        cin>>h[i];
    int mn=INF;
    fd(i,n-1,0)
    {
        if(h[i]<mn)
        {
            mn=h[i];
            dp[i]=i;
        }
        else
            dp[i]=dp[i+1];
    }
    int i=0,ans=0;
    while(i<n)
    {
        int idx=dp[i];
        ans++;
        i=idx+1;
    }
    cout<<ans<<endl;
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int t[100010];

void upd(int x)
{
    while(x<100010)
    {
        t[x]++;
        x+=(x&-x);
    }
}

int get(int x)
{
    int ret=0;
    while(x)
    {
        ret+=t[x];
        x-=(x&-x);
    }
    return ret;
}

int h[100010],a[100010],inv[100010];
int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
    {
        cin>>h[i];
        a[i]=h[i];
    }
    sort(a,a+n);
    fi(i,0,n)
        h[i]=(int)(lower_bound(a,a+n,h[i])-a)+1;
    fd(i,n-1,0)
    {
        inv[i]=get(h[i]-1);
        upd(h[i]);
    }
    int i=0,ans=0;
    while(i<n)
    {
        int val=h[i],rem=inv[i];
        int j=i+1;
        while(j<n&&rem)
        {
            if(h[j]<val)
                rem--;
            else if(h[j]>val)
            {
                val=h[j];
                rem=inv[j];
            }
            j++;
        }
        ans++;
        i=j;
    }
    cout<<ans<<endl;
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int h[100010];
int dp[100010];
int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
        cin>>h[i];
    int mn=INF,last=-1;
    fd(i,n-1,0)
    {
        if(h[i]<mn)
        {
            mn=h[i];
            dp[i]=i;
            last=i;
        }
        else if(h[i]==mn)
            dp[i]=i;
        else
            dp[i]=last;
    }
    int i=0,ans=0;
    while(i<n)
    {
        int idx=dp[i];
        ans++;
        i=idx+1;
    }
    cout<<ans<<endl;
    return 0;
}


//techwiz911
#include<bits/stdc++.h>
#define pb push_back
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define gcd __gcd
#define b_c __builtin_popcount
#define mp make_pair
#define in insert
#define er erase
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define tr(c,it) for(typeof(c).begin() it=(c).begin();it!=(c).end();it++)
#define X first
#define Y second
#define init(a,b) memset(a,b,sizeof(a))
#define n_p next_permutation
#define b_s binary_search
#define endl '\n'
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define INF INT_MAX
#define INFL LLONG_MAX
#define trace1(x)                cerr <<#x<<": "<<x<<endl;
#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef set<int> SI;
typedef set<LL> SLL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

void FastIO()
{ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);}
LL modpow(LL a, LL p, LL mod)
{LL ret=1;while(p){if(p&1)ret=(ret*a)%mod;a=(a*a)%mod;p/=2;}return ret%mod;}
LL power(LL a, LL p)
{LL ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;}
//Template Ends Here

int a[100010],h[100010];
int last[100010],dp[100010];
int main()
{
    FastIO();

    int n;
    cin>>n;
    fi(i,0,n)
    {
        cin>>h[i];
        a[i]=h[i];
    }
    sort(a,a+n);
    fi(i,0,n)
        h[i]=(int)(lower_bound(a,a+n,h[i])-a);
    fi(i,0,n)
        last[i]=-1;
    fd(i,n-1,0)
        if(last[h[i]]==-1)
            last[h[i]]=i;
    dp[0]=last[0];
    fi(i,1,n)
        dp[i]=max(dp[i-1],last[i]);
    int i=0,ans=0;
    while(i<n)
    {
        if(h[i]==0)
        {
            ans++;
            i++;
            continue;
        }
        int idx=dp[h[i]-1];
        i=max(i,idx)+1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
int main()
{
	int T;
	cin>>T;
		int n;
		cin>>n;
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)  cin>>a[i];
		int sum=0;
		a[n+1]=0x3f3f3f3f;
		int l=0;
		for(int i=l;i<=n;i++)
		{
			if(a[l]>a[i+1])  continue;
			else
			{
				sum++;
				l=i+1;
			}
		}
	cout<<sum<<endl<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
int main()
{
		int n;
		cin>>n;
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)  cin>>a[i];
		int sum=0;
		a[n]=0x3f3f3f3f;
		int l=0;
		for(int i=l;i<n;i++)
		{
			if(a[l]>a[i+1])  continue;
			else
			{
				sum++;
				l=i+1;
			}
		}
	cout<<sum<<endl<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
int main()
{

		int n;
		cin>>n;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)  cin>>a[i];
		int sum=1;
		a[0]=0x3f3f3f3f;
		for(int i=0;i<n;i++)
		{
			if(a[i]>a[i+1])  continue;
			else sum++;
		}
		cout<<sum<<endl<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
int main()
{
		int n;
		cin>>n;
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)  cin>>a[i];
		int sum=0;
		a[n]=0x3f3f3f3f;
		int l=0;
		for(int i=l;i<n;i++)
		{
			if(a[l]>a[i+1])  continue;
			else
			{
				sum++;
				l=i+1;
			}
		}
		cout<<sum<<endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
vector<pair<int,int> >g;
int h[100000],num,n,ma,mi,max1,min1;
int check(int a,int b,int c,int d)
{
    if(b>c && a<c || c<b && d>b)
    {
        max1=max(b,d);
        min1=min(a,c);
        return 1;
    }
    else
        return 0;
}
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(int i=0;i<n;i++)
    {
        ma=h[i];
        while(h[i]>h[i+1] && i+1<n)
            {
                i++;
            }
        mi=h[i];
        g.push_back(make_pair(mi,ma));
        num++;
    }
    for(int i=1;i<g.size();i++)
        {
            num-=check(g[i].first,g[i].second,g[i-1].first,g[i-1].second);
            if(check(g[i].first,g[i].second,g[i-1].first,g[i-1].second))
            {g[i].first=min1;
            g[i].second=max1;
            }
        }
    printf("%d\n",num);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100000],prefmax[100000],suffmin[100000],n;
int res;
int main()
{
   //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
    for(int i=0;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
    if(res==0)
        printf("1\n",res);
    else
        printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100000],prefmax[100000],suffmin[100000],n;
int res;
int main()
{
   //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
        prefmax[0]=-1;
    for(int i=0;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
        printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100000],prefmax[100000],suffmin[100000],n;
int res;
int main()
{
   //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
    for(int i=0;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
    printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100000],prefmax[100000],suffmin[100000],n;
int res;
int main()
{
   freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
    for(int i=1;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
    printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100001],prefmax[100001],suffmin[100001],n;
int res;
int main()
{
   //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
        prefmax[0]=-1;
    for(int i=0;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
        printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
vector<pair<int,int> >g;
int h[100000],lal[100000],num,n,ma,mi,max1,min1;
int check(int a,int b,int c,int d)
{
    if(b>c && a<=c || c<=a && d>a)
    {
        max1=max(b,d);
        min1=min(a,c);
        return 1;
    }
    else
        return 0;
}
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(int i=0;i<n;i++)
    {
        ma=h[i];
        while(h[i]>h[i+1] && i+1<n)
            {
                i++;
            }
        mi=h[i];
        g.push_back(make_pair(mi,ma));
        num++;
    }
    for(int i=1;i<g.size();i++)
            for(int j=0;j<i;j++)
            {
                if(!lal[j])
                if(check(g[i].first,g[i].second,g[j].first,g[j].second))
            {g[i].first=min1;
            g[i].second=max1;
            num--;
            lal[j]=1;
            }
        }
    printf("%d\n",num);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
vector<pair<int,int> >g;
int h[100000],num,n,ma,mi,max1,min1;
int check(int a,int b,int c,int d)
{
    if(b>c && a<c || c<a && d>a)
    {
        max1=max(b,d);
        min1=min(a,c);
        return 1;
    }
    else
        return 0;
}
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(int i=0;i<n;i++)
    {
        ma=h[i];
        while(h[i]>h[i+1] && i+1<n)
            {
                i++;
            }
        mi=h[i];
        g.push_back(make_pair(mi,ma));
        num++;
    }
    for(int i=1;i<g.size();i++)
        {
            if(check(g[i].first,g[i].second,g[i-1].first,g[i-1].second))
            {g[i].first=min1;
            g[i].second=max1;
            num--;
            }
        }
    printf("%d\n",num);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
vector<pair<int,int> >g;
int h[100000],lal[100000],num,n,ma,mi,max1,min1;
int check(int a,int b,int c,int d)
{
    if(b>c && a<c || c<a && d>a)
    {
        max1=max(b,d);
        min1=min(a,c);
        return 1;
    }
    else
        return 0;
}
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(int i=0;i<n;i++)
    {
        ma=h[i];
        while(h[i]>h[i+1] && i+1<n)
            {
                i++;
            }
        mi=h[i];
        g.push_back(make_pair(mi,ma));
        num++;
    }
    for(int i=1;i<g.size();i++)
            for(int j=0;j<i;j++)
            {
                if(!lal[j])
                if(check(g[i].first,g[i].second,g[j].first,g[j].second))
            {g[i].first=min1;
            g[i].second=max1;
            num--;
            lal[j]=1;
            }
        }
    printf("%d\n",num);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int h[100000],prefmax[100000],suffmin[100000],n;
int res;
int main()
{
   //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    for(int i=1;i<=n;i++)
        prefmax[i]=max(h[i],prefmax[i-1]);
    suffmin[n]=h[n];
    for(int i=n-1;i>0;i--)
        suffmin[i]=min(h[i],suffmin[i+1]);
    for(int i=1;i<n;i++)
        if(prefmax[i]<=suffmin[i+1])
            res++;
    printf("%d\n",res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
vector<pair<int,int> >g;
int h[100000],lal[100000],num,n,ma,mi,max1,min1;
int check(int a,int b,int c,int d)
{
    if(b>=c && a<=c || c<=a && d>=a)
    {
        if(b==c)
            return 0;
        else{
        max1=max(b,d);
        min1=min(a,c);
        return 1;}
    }
    else
        return 0;
}
int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(int i=0;i<n;i++)
    {
        ma=h[i];
        while(h[i]>h[i+1] && i+1<n)
            {
                i++;
            }
        mi=h[i];
        g.push_back(make_pair(mi,ma));
        num++;
    }
    for(int i=1;i<g.size();i++)
            for(int j=0;j<i;j++)
            {
                if(!lal[j])
                if(check(g[j].first,g[j].second,g[i].first,g[i].second))
            {g[i].first=min1;
            g[i].second=max1;
            num--;
            lal[j]=1;
            }
        }
    printf("%d\n",num);
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<=i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}
//
//int minNumToLeft(int i){
//
//    if(i==0)
//        return -1;
//    else{
//        int minret = -1;
//        for(int j = 0; j<i; j++){
//            if(minret>a[j])
//                minret = a[j];
//        }
//        return minret;
//    }
//}

int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>=i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);
    //int currentmin = a[0];

    int block = 0;

    for(int i = 0; i<n; i++){
        //currentmin = min(a[i],currentmin);
        if(maxNumToLeft(i)<=minNumToRight(i+1)){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}

int minNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int minret = -1;
        for(int j = 0; j<i; j++){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

/*int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}*/

int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);

    int block = 1;

    for(int i = 1; i<n; i++){
        if(a[i]>=maxNumToLeft(i) && !(a[i]<=minNumToLeft(i))){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

    /*for(int i = 0; i<partitions.size();i++){
        for(int j= 0; j<partitions[i].size(); j++){
            cout<<partitions[i][j]<<" ";
        }
        cout<<endl;
    }*/

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100005
using namespace std;
typedef long long int ll;
ll a[SIZE];
ll n;
ll mitl[SIZE],matr[SIZE];

int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    mitl[0]=a[0];
    for(int i=1;i<n;++i) mitl[i]=max(mitl[i-1],a[i]);
       matr[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) matr[i]=min(matr[i+1],a[i]);

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);

    int block = 1;

    for(int i = 0; i<n-1; i++){

        if(mitl[i]<=matr[i+1]){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}

int minNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int minret = -1;
        for(int j = 0; j<i; j++){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
//    freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);
    int currentmin = a[0];

    int block = 1;

    for(int i = 1; i<n; i++){
        currentmin = min(a[i],currentmin);
        if(a[i]>=maxNumToLeft(i) && !(a[i]<=minNumToLeft(i)) && currentmin<=minNumToRight(i)){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}

int minNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int minret = -1;
        for(int j = 0; j<i; j++){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);
    int currentmin = a[0];

    int block = 1;

    for(int i = 1; i<n; i++){
        currentmin = min(a[i],currentmin);
        if(a[i]>=maxNumToLeft(i) && currentmin<=minNumToRight(i)){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100000];

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

    int blockCount=1;
    int previousMax=a[0];

    for(int i = 1; i<n; i++){
        if(previousMax<=a[i]){
            blockCount++;
            previousMax = a[i];
        }
    }

    cout<<blockCount;

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return a[i];
    else{
        int maxret = -1;
        for(int j = 0; j<=i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}

int minNumToRight(int i){

    if(i==n-1)
        return int(a[i]);
    else{
        int minret = (a[i]);
        for(int j = n-1; j>=i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);

    int block = 1;

    for(int i = 0; i<n-1; i++){

        if(maxNumToLeft(i)<=minNumToRight(i+1)){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<=i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}
//
//int minNumToLeft(int i){
//
//    if(i==0)
//        return -1;
//    else{
//        int minret = -1;
//        for(int j = 0; j<i; j++){
//            if(minret>a[j])
//                minret = a[j];
//        }
//        return minret;
//    }
//}

int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>=i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
    freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

//    vector<vector<int> > partitions;
//    vector<int> currentpartition;
//    currentpartition.push_back(a[0]);
    //int currentmin = a[0];

    int block = 0;

    for(int i = 0; i<n; i++){
        //currentmin = min(a[i],currentmin);
        if(maxNumToLeft(i)<=minNumToRight(i+1)){
            block++;
//            partitions.push_back(currentpartition);
//            currentpartition.clear();
//            currentpartition.push_back(a[i]);
        }
//        else{
//            currentpartition.push_back(a[i]);
//        }
    }
//    partitions.push_back(currentpartition);

    cout<<block<<endl;

//    for(int i = 0; i<partitions.size();i++){
//        for(int j= 0; j<partitions[i].size(); j++){
//            cout<<partitions[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    return 0;
}


#include <iostream>
#include <algorithm>

#define SIZE 100000
using namespace std;

int a[SIZE];
int n;

int maxNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int maxret = -1;
        for(int j = 0; j<i; j++){
            if(maxret<a[j])
                maxret = a[j];
        }
        return maxret;
    }
}

int minNumToLeft(int i){

    if(i==0)
        return -1;
    else{
        int minret = -1;
        for(int j = 0; j<i; j++){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int minNumToRight(int i){

    if(i==n-1)
        return int(1e9 + 1);
    else{
        int minret = int(1e9+1);
        for(int j = n-1; j>i; j--){
            if(minret>a[j])
                minret = a[j];
        }
        return minret;
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    cin>>n;

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

    vector<vector<int> > partitions;
    vector<int> currentpartition;
    currentpartition.push_back(a[0]);

    int block = 1;

    for(int i = 1; i<n; i++){
        if(a[i]>=maxNumToLeft(i) && !(a[i]<=minNumToLeft(i))){
            block++;
            partitions.push_back(currentpartition);
            currentpartition.clear();
            currentpartition.push_back(a[i]);
        }
        else{
            currentpartition.push_back(a[i]);
        }
    }
    partitions.push_back(currentpartition);

    cout<<block<<endl;

    /*for(int i = 0; i<partitions.size();i++){
        for(int j= 0; j<partitions[i].size(); j++){
            cout<<partitions[i][j]<<" ";
        }
        cout<<endl;
    }*/

    return 0;
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR (a,begin,end,b) for(int i=begin;i<end;i++)a[i]=b;
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)
int a[SIZE];
int MIN[SIZE];
int main()
{
    int n;

    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];

        int tempMIN = INF;

        for(int i = n - 1; i >= 0; i--)
        {
            tempMIN = min(tempMIN, a[i]);
            MIN[i] = tempMIN;
        }

        int ans = 1;
        int tempMAX = a[0];

        for(int i = 1; i < n; i++)
        {
            if(tempMAX <= MIN[i])
            {
                ans++;
                tempMAX = a[i - 1];
            }

            tempMAX = max(a[i], tempMAX);
        }

        cout << ans << endl;
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;

#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)
int a[SIZE];
int MIN[SIZE];
int main()
{
    int n;

    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 0; i < n; i++)
            scanf("%d",&a[i]);

        int tempMIN = INF;

        for(int i = n - 1; i >= 0; i--)
        {
            tempMIN = min(tempMIN, a[i]);
            MIN[i] = tempMIN;
        }

        int ans = 1;
        int tempMAX = a[0];

        for(int i = 1; i < n; i++)
        {
            if(tempMAX <= MIN[i])
            {
                ans++;
                tempMAX = a[i - 1];
            }

            tempMAX = max(a[i], tempMAX);
        }

        printf("%d\n",ans);
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR (a,begin,end,b) for(int i=begin;i<end;i++)a[i]=b;
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)

int main()
{
    int n;
    int a[SIZE];

    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];

        int ans = 0;

        for(int i = 0; i < n - 1;)
        {
            stack<int>s;
            s.push(a[i]);
            int flag = 0;

            if(a[i + 1] > a[i])
                flag = 1;
            else if(a[i + 1] < a[i])
                flag = -1;
            else
            {
                s.push(a[i]);
                i++;
            }

            for(; i < n - 1;)
            {
                i++;

                if(flag == 1)
                {
                    if(a[i] >= s.top())
                        s.push(a[i]);
                    else
                    {
                        ans = std::max(ans, (int)s.size());

                        if(s.size() > 2)
                            i--;

                        stack<int>em;
                        swap(s, em);
                        break;
                    }
                }
                else if(flag == -1)
                {
                    if(a[i] <= s.top())
                        s.push(a[i]);
                    else
                    {
                        ans = std::max(ans, (int)s.size());

                        if(s.size() > 2)
                            i--;

                        stack<int>em;
                        swap(s, em);
                        break;
                    }
                }
            }

            ans = max(ans, (int)s.size());
        }

        cout << ans << endl;
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR (a,begin,end,b) for(int i=begin;i<end;i++)a[i]=b;
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)

int main()
{
    int n;
    int a[SIZE];

    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];

        int ans = 0;

        for(int i = 0; i < n - 1;)
        {
            stack<int>s;
            s.push(a[i]);
            int flag = 0;

            if(a[i + 1] > a[i])
                flag = 1;
            else if(a[i + 1] < a[i])
                flag = -1;
            else
            {
                s.push(a[i]);
                i++;
            }

            for(; i < n - 1;)
            {
                i++;

                if(flag == 1)
                {
                    if(a[i] >= s.top())
                        s.push(a[i]);
                    else
                    {
                        ans = std::max(ans, (int)s.size());

                        if(s.size() > 2)
                            i--;

                        stack<int>em;
                        s.swap(em);
                        break;
                    }
                }
                else if(flag == -1)
                {
                    if(a[i] <= s.top())
                        s.push(a[i]);
                    else
                    {
                        ans = std::max(ans, (int)s.size());

                        if(s.size() > 2)
                            i--;

                        stack<int>em;
                        s.swap(em);
                        break;
                    }
                }
            }

            ans = max(ans, (int)s.size());
        }

        cout << ans << endl;
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR (a,begin,end,b) for(int i=begin;i<end;i++)a[i]=b;
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)
int a[SIZE];
int MAX[SIZE], MIN[SIZE];
int main()
{
    int n;

    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];

        int tempMAX = -INF;

        for(int i = 0; i < n; i++)
        {
            tempMAX = max(tempMAX, a[i]);
            MAX[i] = tempMAX;
        }

        int tempMIN = INF;

        for(int i = n - 1; i >= 0; i--)
        {
            tempMIN = min(tempMIN, a[i]);
            MIN[i] = tempMIN;
        }

        int pos = 0;
        int ans = 0;

        for(int i = 0; i < n; i++)
        {
            if(MAX[pos] <= MIN[i])
            {
                pos = i;
                ans++;
            }
        }

        cout << ans << endl;
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR (a,begin,end,b) for(int i=begin;i<end;i++)a[i]=b;
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)
int a[SIZE];
int MAX[SIZE], MIN[SIZE];
int main()
{
    int n;

    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];

        int tempMAX = -INF;

        for(int i = 0; i < n; i++)
        {
            tempMAX = max(tempMAX, a[i]);
            MAX[i] = tempMAX;
        }

        int tempMIN = INF;

        for(int i = n - 1; i >= 0; i--)
        {
            tempMIN = min(tempMIN, a[i]);
            MIN[i] = tempMIN;
        }

        int pos = 0;
        int ans = 1;
        /*

                for(int i = 0; i < n; i++)
                    cout << MAX[i] << " ";

                cout << endl;

                for(int i = 0; i < n; i++)
                    cout << MIN[i] << " ";

                cout << endl;
        */

        for(int i = 1; i < n; i++)
        {
            if(MAX[pos] <= MIN[i])
            {
                /*cout << MAX[pos] << " " << MIN[i] << endl;*/
                pos = i;
                ans++;
            }
        }

        cout << ans << endl;
    }
}


#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <set>
using namespace std;
template <class T1, class T2>inline void gmax(T1 &a, T2 b)
{
    if(b > a)a = b;
}
template <class T1, class T2>inline void gmin(T1 &a, T2 b)
{
    if(b < a)a = b;
}
#define INF (0x7fffffff)
#define eps (1e-6)
#define PI (3.141592654)
#define LL long long
#define SIZE (100000 + 10)
int a[SIZE];
int MIN[SIZE];
int main()
{
    int n;

    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 0; i < n; i++)
            scanf("%d",&a[i]);

        int tempMIN = INF;

        for(int i = n - 1; i >= 0; i--)
        {
            //tempMIN=min(tempMIN,a[i]);
            gmin(tempMIN, a[i]);
            MIN[i] = tempMIN;
        }

        int ans = 1;
        int tempMAX = a[0];

        for(int i = 1; i < n; i++)
        {
            if(tempMAX <= MIN[i])
            {
                ans++;
                tempMAX = a[i - 1];
            }

            //tempMAX=max(tempMAX,a[i]);
            gmax(tempMAX, a[i]);
        }
        printf("%d\n",ans);
    }
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
    int a;
    int b;
};
bool cmp(struct yash p,struct yash p1) {
    if(p.a<p1.a) {
        return true;
    }
    else if(p.a>p1.a) {
        return false;
    }
    else {
        if(p.b<p1.b) {
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    scanf("%d",&n);
    struct yash y[n];
    int x[n];
    int cc[n];
    for(int i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        y[i].b = i;
        y[i].a = x[i];
    }
    sort(y,y+n,cmp);
    for(int i = 0;i<n;i++) {
        cc[y[i].b] = i;
    }
    int ans = 0;
    int st = 0;
    for(int i = 0;i < n;i++) {
        int k = i;
        int j = 0;
        for(j = i+1;j<=cc[k];j++) {
            if(x[j]>=x[k]) {
                k = j;
            }
        }

        ans++;
        i = j-1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
    int a;
    int b;
};
bool cmp(struct yash p,struct yash p1) {
    if(p.a<p1.a) {
        return true;
    }
    else if(p.a>p1.a) {
        return false;
    }
    else {
        if(p.b<p1.b) {
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    scanf("%d",&n);
    struct yash y[n];
    int x[n];
    int cc[n];
    for(int i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        y[i].b = i;
        y[i].a = x[i];
    }
    sort(y,y+n,cmp);
    for(int i = 0;i<n;i++) {
        cc[y[i].b] = i;
    }
    int ans = 0;
    int st = 0;
    for(int i = 0;i < n;i++) {
        int k = i;
        int j = 0;
        for(j = i+1;j<=cc[k];j++) {
            if(x[j]>x[k]) {
                k = j;
            }
        }
        if(n==500) {
            printf("%d ",j);
        }
        ans++;
        i = j-1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
    int a;
    int b;
};
bool cmp(struct yash p,struct yash p1) {
    if(p.a<p1.a) {
        return true;
    }
    else if(p.a>p1.a) {
        return false;
    }
    else {
        if(p.b<p1.b) {
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    scanf("%d",&n);
    struct yash y[n];
    int x[n];
    int cc[n];
    for(int i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        y[i].b = i;
        y[i].a = x[i];
    }
    sort(y,y+n,cmp);
    for(int i = 0;i<n;i++) {
        cc[y[i].b] = i;
    }
    int ans = 0;
    int st = 0;
    for(int i = 0;i < n;i++) {
        int k = i;
        int j = 0;
        for(j = i+1;j<=cc[k];j++) {
            if(x[j]>=x[k]) {
                k = j;
            }
        }
        if(n==500) {
            printf("%d %d\n",x[j-1],j);
        }
        ans++;
        i = j-1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
    int a;
    int b;
};
bool cmp(struct yash p,struct yash p1) {
    if(p.a<p1.a) {
        return true;
    }
    else if(p.a>p1.a) {
        return false;
    }
    else {
        if(p.b<p1.b) {
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    scanf("%d",&n);
    struct yash y[n];
    int x[n];
    int cc[n];
    for(int i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        y[i].b = i;
        y[i].a = x[i];
    }
    sort(y,y+n,cmp);
    for(int i = 0;i<n;i++) {
        cc[y[i].b] = i;
    }
    int ans = 0;
    int st = 0;
    for(int i = 0;i < n;i++) {
        int k = cc[i];
        int j = 0;
        for(j = i+1;j<=cc[i];j++) {
            if(x[j]>x[i]) {
                i = cc[j];
            }
        }
        ans++;
        i = j-1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
	int a;
	int b;
};
bool cmp(struct yash p,struct yash p1) {
	if(p.a<p1.a) {
		return true;
	}
	else if(p.a>p1.a) {
		return false;
	}
	else {
		if(p.b<p1.b) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	int n;
	scanf("%d",&n);
	struct yash y[n];
	int x[n];
	int cc[n];
	for(int i = 0;i < n;i++) {
		scanf("%d",&x[i]);
		y[i].b = i;
		y[i].a = x[i];
	}
	sort(y,y+n,cmp);
	for(int i = 0;i<n;i++) {
		cc[y[i].b] = i;
	}
	int ans = 0;
	int st = 0;
	for(int i = 0;i < n;i++) {
		int k = i;
		int j = 0;
		for(j = i+1;j<=cc[k];j++) {
			if(x[j]>x[k]) {
				k = j;
			}
		}
		if(n==500) {
			printf("%d %d\n",x[j-1],j);
		}
		ans++;
		i = j-1;
	}
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
struct yash {
    int a;
    int b;
};
bool cmp(struct yash p,struct yash p1) {
    if(p.a<p1.a) {
        return true;
    }
    else if(p.a>p1.a) {
        return false;
    }
    else {
        if(p.b<p1.b) {
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    scanf("%d",&n);
    struct yash y[n];
    int x[n];
    int cc[n];
    for(int i = 0;i < n;i++) {
        scanf("%d",&x[i]);
        y[i].b = i;
        y[i].a = x[i];
    }
    sort(y,y+n,cmp);
    for(int i = 0;i<n;i++) {
        cc[y[i].b] = i;
    }
    int ans = 0;
    int st = 0;
    for(int i = 0;i < n;i++) {
        int k = i;
        int j = 0;
        for(j = i+1;j<=cc[k];j++) {
            if(x[j]>x[k]) {
                k = j;
            }
        }
        ans++;
        i = j-1;
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <vector>
using namespace std;

void qs(unsigned long *s_arr, int first, int last)
{
    int i = first, j = last, x = s_arr[(first + last) / 2];

    do {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--;

        if(i <= j) {
            if (s_arr[i] > s_arr[j])
                swap(s_arr[i], s_arr[j]);
            i++;
            j--;
        }
    } while (i <= j);

    if (i < last)
        qs(s_arr, i, last);
    if (first < j)
        qs(s_arr, first, j);
}

int search(unsigned long *arr, bool *visited, int n, unsigned long elem){
    int l = 0, r = n - 1, m = (l + r) / 2;
    while (l < r){
        if (arr[m] < elem || (arr[m] == elem && visited[m])){
            l = m + 1;
        } else r = m;
        m = (l + r) / 2;
    }

    return l;
}

int main(){
    int n, count = 0, s1, s2, tmp;
    cin >> n;
    unsigned long *arr = new unsigned long[n], *s_arr = new unsigned long[n];
    bool *visited = new bool[n];
    for (int i = 0; i < n; ++i){
        cin >> arr[i];
        s_arr[i] = arr[i];
        visited[i] = 0;
    }

    qs(s_arr, 0, n - 1);

    s1 = 0;
    while (s1 < n){
        s2 = search(s_arr, visited, n, arr[s1]);
        visited[s2] = 1;
        for (int i = s1 + 1; i <= s2; ++i){
            tmp = search(s_arr, visited, n, arr[i]);
            visited[tmp] = 1;
            if (tmp > s2)
                s2 = tmp;
        }
        ++count;
        s1 = s2 + 1;
    }
    cout << count << "\n";

    delete [] arr;
    delete [] s_arr;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

void qs(unsigned long *s_arr, int first, int last)
{
    int i = first, j = last, x = s_arr[(first + last) / 2];

    do {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--;

        if(i <= j) {
            if (s_arr[i] > s_arr[j])
                swap(s_arr[i], s_arr[j]);
            i++;
            j--;
        }
    } while (i <= j);

    if (i < last)
        qs(s_arr, i, last);
    if (first < j)
        qs(s_arr, first, j);
}

int search(unsigned long *arr, int n, unsigned long elem){
    int l = 0, r = n - 1, m = (l + r) / 2;
    while (l < r){
        if (arr[m] < elem){
            l = m + 1;
        } else r = m;
        m = (l + r) / 2;
    }

    return l;
}

int main(){
    int n, count = 0, s1, s2, tmp;
    cin >> n;
    unsigned long *arr = new unsigned long [n], *s_arr = new unsigned long[n];
    for (int i = 0; i < n; ++i){
        cin >> arr[i];
        s_arr[i] = arr[i];
    }

    qs(s_arr, 0, n - 1);

    s1 = 0;
    while (s1 < n){
        s2 = search(s_arr, n, arr[s1]);
        for (int i = s1 + 1; i <= s2 && s2 < n - 1; ++i){
            tmp = search(s_arr, n, arr[i]);
            if (tmp > s2)
                s2 = tmp;
        }
        ++count;
        if (s2 < s1)
            s1++;
        else s1 = s2 + 1;
    }
    cout << count << "\n";

    delete [] arr;
    delete [] s_arr;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

void qs(unsigned long *s_arr, int first, int last)
{
    int i = first, j = last, x = s_arr[(first + last) / 2];

    do {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--;

        if(i <= j) {
            if (s_arr[i] > s_arr[j])
                swap(s_arr[i], s_arr[j]);
            i++;
            j--;
        }
    } while (i <= j);

    if (i < last)
        qs(s_arr, i, last);
    if (first < j)
        qs(s_arr, first, j);
}

int search(unsigned long *arr, int s,  int n, unsigned long elem){
    int l = s, r = n - 1, m = (l + r) / 2;
    while (l < r){
        if (arr[m] < elem){
            l = m + 1;
        } else r = m;
        m = (l + r) / 2;
    }

    return l;
}

int main(){
    int n, count = 0, s1, s2, tmp;
    cin >> n;
    unsigned long *arr = new unsigned long [n], *s_arr = new unsigned long[n];
    for (int i = 0; i < n; ++i){
        cin >> arr[i];
        s_arr[i] = arr[i];
    }

    qs(s_arr, 0, n - 1);

    s1 = 0;
    while (s1 < n){
        s2 = search(s_arr, 0, n, arr[s1]);
        for (int i = s1 + 1; i <= s2 && s2 < n - 1; ++i){
            tmp = search(s_arr, i, n, arr[i]);
            if (tmp > s2)
                s2 = tmp;
        }
        ++count;
        if (s2 < s1)
            s1++;
        else s1 = s2 + 1;
    }
    cout << count << "\n";

    delete [] arr;
    delete [] s_arr;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

void qs(unsigned long *s_arr, int first, int last)
{
    int i = first, j = last, x = s_arr[(first + last) / 2];

    do {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--;

        if(i <= j) {
            if (s_arr[i] > s_arr[j])
                swap(s_arr[i], s_arr[j]);
            i++;
            j--;
        }
    } while (i <= j);

    if (i < last)
        qs(s_arr, i, last);
    if (first < j)
        qs(s_arr, first, j);
}

int search(unsigned long *arr, int s,  int n, unsigned long elem){
    int l = s, r = n - 1, m = (l + r) / 2;
    while (l < r){
        if (arr[m] < elem){
            l = m + 1;
        } else r = m;
        m = (l + r) / 2;
    }

    return l;
}

int main(){
    int n, count = 0, s1, s2, tmp;
    cin >> n;
    unsigned long *arr = new unsigned long [n], *s_arr = new unsigned long[n];
    for (int i = 0; i < n; ++i){
        cin >> arr[i];
        s_arr[i] = arr[i];
    }

    qs(s_arr, 0, n - 1);

    s1 = 0;
    while (s1 < n){
        s2 = search(s_arr, s1, n, arr[s1]);
        for (int i = s1 + 1; i <= s2; ++i){
            tmp = search(s_arr, i, n, arr[i]);
            if (tmp > s2)
                s2 = tmp;
        }
        ++count;
        s1 = s2 + 1;
    }
    cout << count << "\n";

    delete [] arr;
    delete [] s_arr;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

void qs(int* s_arr, int first, int last)
{
    int i = first, j = last, x = s_arr[(first + last) / 2];

    do {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--;

        if(i <= j) {
            if (s_arr[i] > s_arr[j])
                swap(s_arr[i], s_arr[j]);
            i++;
            j--;
        }
    } while (i <= j);

    if (i < last)
        qs(s_arr, i, last);
    if (first < j)
        qs(s_arr, first, j);
}

int search(int *arr, int n, int elem){
    int l = 0, r = n - 1, m = (l + r) / 2;
    while (l < r){
        if (arr[m] < elem){
            l = m + 1;
        } else r = m;
        m = (l + r) / 2;
    }

    return l;
}

int main(){
    int n, count, s1, s2, tmp;
    cin >> n;
    bool flag;
    int *arr = new int [n], *s_arr = new int[n];
    for (int i = 0; i < n; ++i){
        cin >> arr[i];
        s_arr[i] = arr[i];
    }

    qs(s_arr, 0, n - 1);

    s1 = 0;
    while (s1 < n){
        s2 = search(s_arr, n, arr[s1]);
        for (int i = s1 + 1; i <= s2; ++i){
            tmp = search(s_arr, n, arr[i]);
            if (tmp > s2)
                s2 = tmp;
        }
        ++count;
        s1 = s2 + 1;
    }
    cout << count << "\n";

    delete [] arr;
    delete [] s_arr;

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    for(int i = 0; i < n; i++) cin >> h[i];
    int res = 1,hed = h[0];
    for(int i = 0; i < n; i++){
        if(h[i] > hed ){
            res++;
            hed = h[i];
        }
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    map<int,int> mp;

    for(int i = 0; i < n; i++) cin >> h[i], mp[i] = h[i];

    sort(h,h+n);
    int res = 1;

    for(int i = 0; i < n-1; i++){
        if(mp[i+1] > mp[i]) res++;
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    map<int,int> mp;

    for(int i = 0; i < n; i++) cin >> h[i], mp[i] = h[i];

    sort(h,h+n);
    int res = 1;

    for(int i = 0; i < n-1; i++){
        if(mp[i+1] < mp[i]) res++;
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    for(int i = 0; i < n; i++) cin >> h[i];
    int res = 1,tmp = 1;
    for(int i = 0; i < n-1; i++){
        if(h[i] <= h[i+1]) tmp++;
        else tmp = 1;
        res = max(res,tmp);
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8
#define MOD (ll)(1e9 + 7)
#define readFile freopen("in.txt","r",stdin)
#define fastIO ios::sync_with_stdio(0)

using namespace std;

int main() {

    //readFile;
    fastIO;
    int n,arr1[123456],arr2[123456];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr1[i], arr2[i] = arr1[i];
    sort(arr2,arr2+n);
    int res = 0,mn = arr2[0];
    for(int i = 0; i < n; i++){
        if(mn == arr1[i]){
            res++;
            mn = arr2[i+1];
        }
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    map<int,int> mp;

    for(int i = 0; i < n; i++) cin >> h[i], mp[i] = h[i];

    int res = 1, hed = h[0];

    for(int i = 0; i < n; i++){
        if(hed < h[i]){
            res++;
            hed = h[i];
        }
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    map<int,int> mp;

    for(int i = 0; i < n; i++) cin >> h[i], mp[i] = h[i];

    int res = 0, hed = h[0];

    for(int i = 0; i < n; i++){

        if(hed <= h[i]){
            res++;
            hed = h[i];
        }
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8
#define MOD (ll)(1e9 + 7)
#define readFile freopen("in.txt","r",stdin)
#define fastIO ios::sync_with_stdio(0)

using namespace std;

int main() {

    //readFile;
    fastIO;
    int n,arr1[123456],arr2[123456];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr1[i], arr2[i] = arr1[i];
    sort(arr2,arr2+n);
    int res = 0,mn = 0;
    for(int i = 0; i < n; i++){
        mn += arr1[i]-arr2[i];
        if(!mn){
            res++;
            mn = 0;
        }
    }
    cout << res << "\n";

    return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(),(v).end()
#define INF int(1e8)
#define NINF int(-1e8)
#define clr(a,v) memset(a,v,sizeof(a))
#define ll long long
#define ull unsigned long long
#define ld long double
#define eps 1e-8

#define MOD (ll)(1e9 + 7)

using namespace std;

int abss(int x){
    return x > 0 ? x : -x;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int n; cin >> n;
    int h[123456];
    for(int i = 0; i < n; i++) cin >> h[i];
    int res = 1,hed = h[0];
    for(int i = 0; i < n-1; i++){
        if(h[i+1] > h[i] ){
            res++;
        }
    }
    cout << res << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = 1000000007;
#define op(x) (x&(-x))
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define si(n) scanf("%d",&n)
#define s2i(x,y) scanf("%d %d",&x,&y);
#define s3i(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define s4i(x,y,z,w) scanf("%d %d %d %d",&x,&y,&z,&w);
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

int main()
{
    int x[100005]={},maxa=INT_MIN,ans=0,n; vector<int> a,b;
    cin>>n;
    FOR(i,0,n) {int num; cin>>num; a.push_back(num); b.push_back(num);}
    sort(b.begin(),b.end());
    FOR(i,0,n)
    {
        int temp = a[i];
        //Now, we have to search for temp in array b
        vector<int>::iterator it = lower_bound(b.begin(),b.end(),temp);
        int num = it-b.begin();
        if(x[num]!=-1)
        {
            x[num]=-1;
            maxa=max(maxa,num);
        }
        else
        {
            while(x[num]!=0&&num<n) num++;
            x[num]=-1;
            maxa=max(maxa,num);
        }
        if(i==maxa)
        {
            ans++;
            maxa=INT_MIN;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = 1000000007;
#define op(x) (x&(-x))
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define si(n) scanf("%d",&n)
#define s2i(x,y) scanf("%d %d",&x,&y);
#define s3i(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define s4i(x,y,z,w) scanf("%d %d %d %d",&x,&y,&z,&w);
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

int main()
{
    int x[100005]={},maxa=INT_MIN,ans=0,n; vector<int> a,b;
    cin>>n;
    FOR(i,0,n) {int num; cin>>num; a.push_back(num); b.push_back(num);}
    sort(b.begin(),b.end());
    FOR(i,0,n)
    {
        int temp = a[i];
        //Now, we have to search for temp in array b
        vector<int>::iterator it = lower_bound(b.begin(),b.end(),temp);
        int num = it-b.begin();
        if(x[num]!=-1)
        {
            x[num]=-1;
            maxa=max(maxa,num);
        }
        else
        {
            while(x[num]!=0) num++;
            maxa=max(maxa,num);
        }
        if(i==maxa)
        {
            ans++;
            maxa=INT_MIN;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = 1000000007;
#define op(x) (x&(-x))
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define si(n) scanf("%d",&n)
#define s2i(x,y) scanf("%d %d",&x,&y);
#define s3i(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define s4i(x,y,z,w) scanf("%d %d %d %d",&x,&y,&z,&w);
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

int main()
{
    int maxa=INT_MIN,ans=0,n; vector<int> a,b;
    map<int,int> m;
    cin>>n;
    FOR(i,0,n) {int num; cin>>num; a.push_back(num); b.push_back(num);}
    sort(b.begin(),b.end());
    int i=0;
    while(i<n)
    {
        m[b[i]]=i;
        int temp = b[i];
        while(i<n&&b[i]==temp) i++;
    }
    FOR(i,0,n)
    {
        int pos = m[a[i]]; m[a[i]]++;
        maxa=max(maxa,pos);
        if(i==maxa)
        {
            ans++;
            maxa=INT_MIN;
        }
    }
    cout<<ans<<endl;
    return 0;
}