#include <bits/stdc++.h>
using namespace std;
int n;
int id[100010], pre[100010], t[100010];
int stk[100010];
int top;
int max(int x, int y) { return x > y ? x : y; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &id[i]);
  top = 0;
  stk[++top] = 0;
  t[0] = 1000000000;
  for (int i = 1; i < n; i++) {
    t[i] = 1;
    while (top > 0 && id[i] > id[stk[top]]) {
      t[i] = max(t[i], t[stk[top]] + 1);
      top--;
    }
    stk[++top] = i;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (t[i] < 1000000000) ans = max(ans, t[i]);
  printf("%d\n", ans);
}
