#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, ans, a[N], nxt[N];
bool erase[N];
queue<int> q;
queue<int> que;
int main() {
  int pre, x, y;
  scanf("%d", &n);
  memset(nxt, -1, sizeof(nxt));
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n - 1; i++) {
    q.push(a[i]);
    nxt[a[i]] = a[i + 1];
  }
  memset(erase, 0, sizeof(erase));
  for (ans = 0;; ans++) {
    while (!q.empty()) {
      x = q.front();
      q.pop();
      if (erase[x] || nxt[x] == -1 || x < nxt[x]) continue;
      que.push(x);
      pre = x;
      while (~nxt[pre] && pre > nxt[pre]) {
        y = nxt[pre];
        erase[y] = 1;
        nxt[x] = nxt[y];
        pre = y;
      }
    }
    while (!que.empty()) {
      q.push(que.front());
      que.pop();
    }
    if (q.empty()) break;
  }
  printf("%d\n", ans);
  return 0;
}
