#include <iostream>
#include <cstdio>
using namespace std;
int n, a[200010], p[200010];
int main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) scanf ("%d", &a[i]), p[a[i]] = i;
    int T = 0, f = 0;
    for (int i = n - 1; i >= 1; i--) {
        if (!T) {
            if (p[i] > p[i + 1]) T = 1, f = i + 1;
            continue;
        }
        if (p[f] <= p[i] && p[i] <= p[i + 1]) continue;
        if (p[i] <= p[i + 1] && p[i + 1] <= p[f]) continue;
        if (p[i + 1] <= p[f] && p[f] <= p[i]) continue;
        T++, f = i + 1;
    }
    printf ("%d\n", T);
    return 0;
} 