#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int T[200010],f[200010],p[200010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)p[gi()]=i;
	for(int i=n-1;i;--i){
		if(!T[i+1]){if(p[i]>p[i+1])T[i]=1,f[i]=i+1;}
		else{
			if((p[i]<p[i+1])+(p[i+1]<p[f[i+1]])+(p[f[i+1]]<p[i])==2)T[i]=T[i+1],f[i]=f[i+1];
			else T[i]=T[i+1]+1,f[i]=i+1;
		}
	}
	printf("%d\n",T[1]);
	return 0;
}
