#include <bits/stdc++.h>
using namespace std;
int n;
int ans;
stack<pair<int, int> > S;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int q;
    cin >> q;
    int surv = 0;
    while (S.size() > 0 && S.top().first < q) {
      surv = max(surv, S.top().second);
      S.pop();
    }
    if (S.size() == 0) {
      S.push(make_pair(q, 1e9));
    } else {
      ans = max(ans, surv + 1);
      S.push(make_pair(q, surv + 1));
    }
  }
  cout << ans << endl;
  return 0;
}
