#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
struct data {
  int vl, step;
} tmp;
int main() {
  int n, arr[100000 + 7], cnt, tym, ans, i, j, k;
  while (scanf("%d", &n) == 1) {
    stack<data> stk;
    for (i = 1; i <= n; i++) {
      scanf("%d", &arr[i]);
    }
    ans = 0;
    tmp.vl = arr[n];
    tmp.step = 0;
    stk.push(tmp);
    for (i = n - 1; i > 0; i--) {
      cnt = 1;
      while (!stk.empty() and stk.top().vl < arr[i]) {
        ans = max(ans, cnt);
        cnt = max(cnt, stk.top().step);
        stk.pop();
        cnt++;
      }
      tmp.vl = arr[i];
      tmp.step = cnt - 1;
      stk.push(tmp);
    }
    printf("%d\n", ans);
  }
  return 0;
}
