#include <bits/stdc++.h>
using namespace std;

int a[200010];
int q[200010];
int T[200010];
int f[200010];
int n;
int cnt;

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++) q[a[i]]=i;
	
	for (int i=n-1;i;i--)  
    {  
        if( !T[ i + 1 ] )  
        {  
            if( q[i] > q[i+1] ) T[i]=1, f[i]=i+1;  
            else T[i] = 0;  
        }  
        else  
        {  
            int cnt = 0;  
            cnt += q[f[i+1]] < q[i];  
            cnt += q[i] < q[i+1];  
            cnt += q[i+1] < q[f[i+1]];  
            if (cnt==2) T[i]=T[i+1],f[i]=f[i+1];  
            else T[i]=T[i+1]+1,f[i]=i+1;  
        }  
    }  
    cout<<T[1];
}