#include <cstdio>
const int maxn = 200005;
int N, p[maxn], q[maxn];
bool c(int x, int y, int z) {
	if(q[x] < q[y]) return q[z] < q[x] or q[y] < q[z];
	return q[y] < q[z] and q[z] < q[x];
}
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) scanf("%d", p + i);
	for(int i = 1; i <= N; ++i) q[p[i]] = i;
	int t = 0, f = -1;
	for(int i = N - 1; i; --i) {
		if(t == 0) {
			if(q[i] > q[i + 1]) t = 1, f = i + 1;
		} else {
			if(!c(i, i + 1, f)) t = t + 1, f = i + 1;
		}
	}
	printf("%d\n", t);
	return 0;
}