#include <bits/stdc++.h>
using namespace std;
pair<int, int> stk[100010];
int a[100010], top;
int main() {
  int n, i, cur, ret;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (ret = top = 0, i = n - 1; ~i; --i) {
      for (cur = 0; top && a[i] > stk[top].first; --top) {
        cur = max(cur + 1, stk[top].second);
      }
      stk[++top] = make_pair(a[i], cur);
      ret = max(ret, cur);
    }
    printf("%d\n", ret);
  }
  return 0;
}
