#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n;
  cin >> n;
  stack<pair<int, int> > x;
  for (int i = 0; i < n; ++i) cin >> a[i];
  x.push(make_pair(a[0], 0));
  int t = 0;
  int max_t = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] < x.top().first) {
      x.push(make_pair(a[i], t + 1));
      max_t = max(t + 1, max_t);
    } else {
      int tt = 0;
      while (!x.empty() && x.top().first < a[i]) {
        tt = max(tt, x.top().second);
        x.pop();
      }
      if (x.empty()) {
        x.push(make_pair(a[i], 0));
      } else {
        x.push(make_pair(a[i], tt + 1));
        max_t = max(tt + 1, max_t);
      }
    }
  }
  cout << max_t;
  return 0;
}
