#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  vector<int> data;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    data.push_back(v);
  }
  stack<pair<int, int> > si;
  int res = 0;
  si.push(make_pair(data[n - 1], 0));
  for (int i = n - 2; i >= 0; --i) {
    int op = 0;
    while (!si.empty()) {
      pair<int, int> t = si.top();
      if (t.first > data[i]) {
        break;
      }
      op = max(op + 1, t.second);
      si.pop();
    }
    si.push(make_pair(data[i], op));
    res = max(op, res);
  }
  cout << res << endl;
  return EXIT_SUCCESS;
}
