#include <bits/stdc++.h>
using namespace std;
struct DT {
  int v, p;
  void set(int a, int b) {
    v = a;
    p = b;
  }
} ob;
vector<DT> v;
stack<DT> stk;
int step[100010];
int main() {
  int n, x, ans, cnt;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    ob.set(x, i);
    ;
    v.push_back(ob);
  }
  ob.set(100010, n + 1);
  stk.push(ob);
  ans = 0;
  for (int i = v.size() - 1; i >= 0; i--) {
    cnt = 0;
    while (v[i].v > (stk.top()).v) {
      ob = stk.top();
      cnt++;
      cnt = step[v[i].p] = max(step[ob.p], cnt);
      stk.pop();
    }
    ans = max(ans, step[v[i].p]);
    stk.push(v[i]);
  }
  cout << ans << endl;
  return 0;
}
