#include <bits/stdc++.h>
using namespace std;
stack<pair<int, int> > stc;
int main() {
  ios::sync_with_stdio(false);
  int n, men, i, cur_max, max;
  cin >> n;
  cin >> men;
  stc.push(make_pair(men, 0));
  max = 0;
  for (i = 0; i < n - 1; i++) {
    cin >> men;
    if (stc.top().first > men) {
      stc.push(make_pair(men, 1));
      if (max == 0) max = 1;
      continue;
    }
    cur_max = 0;
    while (true) {
      if (stc.top().first > men) {
        if (stc.top().second > cur_max || stc.top().second == 0) {
          stc.push(make_pair(men, cur_max + 1));
          if (max < cur_max + 1) max = cur_max + 1;
          break;
        }
        stc.pop();
      } else {
        if (stc.top().second == 0) {
          stc.push(make_pair(men, 0));
          break;
        }
        if (stc.top().second > cur_max) cur_max = stc.top().second;
        if (max < cur_max) max = cur_max;
        stc.pop();
      }
    }
  }
  cout << max << endl;
  return 0;
}
