#include <bits/stdc++.h>
int a[100001], next[100001];
int n, u, v, w, ans;
int h1, h2, q1[100001], q2[100001];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    next[i - 1] = i;
  }
  for (int i = 1; i < n; i++)
    if (a[i] > a[i + 1]) q1[++h1] = i;
  while (h1) {
    ans++;
    h2 = 0;
    for (int i = h1; i > 0; i--) {
      u = q1[i];
      v = next[u];
      next[u] = next[v];
      if (next[v] && a[u] > a[next[v]]) q2[++h2] = u;
    }
    for (int i = 1; i <= h2; i++) q1[h2 - i + 1] = q2[i];
    h1 = h2;
  }
  printf("%d", ans);
  return 0;
}
