#include <bits/stdc++.h>
using namespace std;
int N, a[100005];
stack<pair<int, int> > s;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  int ret = 0;
  for (int i = N - 1; i >= 0; i--) {
    int step = 0;
    while (s.size() > 0 && a[i] > s.top().first) {
      step = max(step + 1, s.top().second);
      s.pop();
    }
    ret = max(ret, step);
    s.push({a[i], step});
  }
  cout << ret << endl;
  return 0;
}
