#include <bits/stdc++.h>

const int MAXN = 200010;
int at[MAXN], A[MAXN], n;
bool chk(int a, int b, int c) {
	return (a < b) + (b < c) + (c < a) == 2;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i], at[A[i]] = i;
	int T = 0, f = -1;
	for (int i = n - 1; i; --i)
		if (!T) {
			if (at[i] > at[i + 1]) ++T, f = i + 1;
		} else if (!chk(at[f], at[i], at[i + 1])) ++T, f = i + 1;
	std::cout << T << std::endl;
	return 0;
}
