#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int p[N],n,x;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		p[x]=i;
	}
	int now=n-1;
	while (now&&p[now]<p[now+1])now--;
	if (!now){
		puts("0");
		return 0;
	}
	int ans=1,pre=now+1;
	for (;now;now--){
		if (p[pre]<=p[now]&&p[now]<=p[now+1])continue;
		if (p[now]<=p[now+1]&&p[now+1]<=p[pre])continue;
		if (p[now+1]<=p[pre]&&p[pre]<=p[now])continue;
		ans++;pre=now+1;
	}
	printf("%d",ans);
	return 0;
}
