
#include <bits/stdc++.h>

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, a[nsz + 5], rt, lst, ans;
int ql, qr, q[2 * nsz + 5];

struct treap {
	int sz, ls[nsz + 5], rs[nsz + 5], pri[nsz + 5];
	int key[nsz + 5], mn[nsz + 5], mx[nsz + 5];
	
	int inline node(int w) {
		int u = ++sz;
		key[u] = mn[u] = mx[u] = w, pri[u] = rand();
		return u;
	}
	
	void inline up(int u) {
		mn[u] = ls[u] ? mn[ls[u]] : key[u];
		mx[u] = rs[u] ? mx[rs[u]] : key[u];
	}
	
	int merge(int v1, int v2) {
		if (!v1 || !v2)  return v1 | v2;
		return pri[v1] < pri[v2] ? (rs[v1] = merge(rs[v1], v2), up(v1), v1) : (ls[v2] = merge(v1, ls[v2]), up(v2), v2);
	}
	
	void split(int u, int w, int &v1, int &v2) {
		if (!u) { v1 = v2 = 0; return; }
		key[u] <= w ? (v1 = u, split(rs[u], w, rs[u], v2), up(u)) : (v2 = u, split(ls[u], w, v1, ls[u]), up(u));
	}
	
	void inline push_back(int &rt, int w) { rt = merge(rt, node(w)); }
	
	void inline pop_back(int &rt, int w) { int v; split(rt, w - 1, rt, v); }
};
treap tr;

void inline init() {
	cont (i, n) {
		tr.push_back(q[qr], a[i]);
		if (i != n && a[i] > a[i + 1])  ++qr;
	}
	for (lst = n; tr.mx[q[qr]] == lst && lst; tr.pop_back(q[qr], lst--));
	
	++qr;
}

void inline deal() {
	for (++ans; !q[ql] && ql != qr; ++ql);
	int u = q[ql++], mx = tr.mx[u], v1, v2;
	for (int k = ql; k != qr && mx != lst; ++k) {
		if (!q[k])  continue;
		if (tr.mx[q[k]] > mx) {
			tr.split(q[k], mx, v1, v2);
			q[k] = v1, u = tr.merge(u, v2);
			mx = tr.mx[u];
		}
		int &r1 = q[k - 1], &r2 = q[k];
		if (r1 && tr.mx[r1] < tr.mn[r2])  r2 = tr.merge(r1, r2), r1 = 0;
	}
	int &r1 = q[qr - 1], &r2 = u;
	if (r1 && tr.mx[r1] < tr.mn[r2])  r2 = tr.merge(r1, r2), r1 = 0;
	for (; tr.mx[u] == lst && lst; tr.pop_back(u, lst--));
	q[qr++] = u;
}

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
	}
	for (init(); lst; deal());
	printf("%d\n", ans);
}