#include <bits/stdc++.h>
using namespace std;
pair<int, int> stk[100100];
int tt;
int main() {
  int n, ans = 0, x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    scanf("%d", &x);
    while (tt > 0 && stk[tt].first < x) {
      tmp = max(tmp, stk[tt].second);
      tt--;
    }
    stk[++tt] = {x, tt ? tmp + 1 : 0};
    ans = max(ans, stk[tt].second);
  }
  printf("%d\n", ans);
  return 0;
}
