#include <bits/stdc++.h>
const int Maxn = 100005;
int next[Maxn], a[Maxn], o[Maxn];
bool cut[Maxn];
int main() {
  int n, i;
  scanf("%d", &n);
  next[n] = n + 1;
  a[n + 1] = n + 1;
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    next[i] = i + 1;
  }
  int m = 0;
  for (i = n - 1; i; --i)
    if (a[i] > a[i + 1]) o[m++] = i;
  int m0, p, step = 0;
  while (m) {
    ++step;
    m0 = m, m = 0;
    for (i = 0; i < m0; ++i) {
      p = o[i];
      if (cut[p]) continue;
      cut[next[p]] = true;
      next[p] = next[next[p]];
      if (a[p] > a[next[p]]) o[m++] = p;
    }
  }
  printf("%d\n", step);
  return 0;
}
