#include <cstdio>
#include <algorithm>
#include <cctype>
#include <ctime>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
int n, f[N], t[N], p[N];
bool cycle(int a, int b, int c) { return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b); }
int main()
{
    n = read(); 
    for(int i = 1; i <= n; ++i) p[read()] = i;
    for(int i = n-1; i; --i)
        if(t[i+1])
        {
            if(cycle(p[f[i+1]], p[i], p[i+1])) t[i] = t[i+1], f[i] = f[i+1];
            else t[i] = t[i+1]+1, f[i] = i+1;
        }
        else if(p[i] > p[i+1]) t[i] = 1, f[i] = i+1;
    printf("%d\n", t[1]);
    return 0;
}