#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
int nex[MAXN], pre[MAXN], n, tail[2], que[2][MAXN], a[MAXN], d[MAXN], tot,
    e[MAXN], tote;
bool del[MAXN], upd[MAXN];
void Del(int x) { nex[pre[x]] = nex[x], pre[nex[x]] = pre[x]; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  a[0] = 0, a[n + 1] = n + 1;
  for (int i = 1; i <= n; ++i) nex[a[i]] = a[i + 1], pre[a[i]] = a[i - 1];
  for (int i = 1; i <= n; ++i) que[0][++tail[0]] = i;
  del[0] = del[n + 1] = true;
  for (int CC = 1; CC <= n; ++CC) {
    int i = CC & 1, i1 = i ^ 1;
    tot = 0;
    tote = 0;
    for (int j = 1; j <= tail[i1]; ++j)
      if (pre[que[i1][j]] > que[i1][j])
        del[que[i1][j]] = true, upd[nex[que[i1][j]]] = true,
        d[++tot] = que[i1][j], e[++tote] = nex[que[i1][j]];
    if (!tot) {
      printf("%d\n", CC - 1);
      break;
    }
    for (int j = 1; j <= tot; ++j) Del(d[j]);
    tail[i] = 0;
    for (int j = 1; j <= tote; ++j)
      if (!del[e[j]]) que[i][++tail[i]] = e[j];
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
