#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 100 + 10, INF = 1e9 + 10;
int a[MAXN], tt[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    tt[i] = INF;
  }
  vector<pair<int, int> > v;
  v.push_back(make_pair(a[0], 0));
  int mx = 0;
  for (int i = 0; i < n; i++) {
    int j = 0, maxTime = 0;
    while (((int)v.size()) > 0) {
      pair<int, int> tmp = v.back();
      int w = tmp.first, t = tt[tmp.second], dis = maxTime;
      if (w > a[i] && t >= dis) {
        tt[i] = dis + 1;
        break;
      }
      maxTime = max(maxTime, t);
      j++;
      v.pop_back();
    }
    v.push_back(make_pair(a[i], i));
    if (tt[i] != INF) mx = max(mx, tt[i]);
  }
  cout << mx << endl;
  return 0;
}
