#include <bits/stdc++.h>
using namespace std;
int jwb = 0, n;
stack<pair<int, int> > stek;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    int maks = 0;
    while (!stek.empty() and stek.top().first < tmp) {
      maks = max(maks, stek.top().second);
      stek.pop();
    }
    if (stek.empty()) {
      stek.push(pair<int, int>(tmp, 0));
    } else {
      stek.push(pair<int, int>(tmp, maks + 1));
      jwb = max(jwb, maks + 1);
    }
  }
  cout << jwb << endl;
}
