#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<pair<int, int>> stk;
  int N;
  cin >> N;
  int ans = -1;
  for (int i = 0; i < N; ++i) {
    int curr_psycho;
    int killed = 0;
    cin >> curr_psycho;
    while (!stk.empty() && stk.top().first < curr_psycho) {
      killed = stk.top().second + 1;
      stk.pop();
    }
    if (stk.empty()) {
      killed = N + 1;
    }
    if (killed <= N && killed > ans) ans = killed;
    while (!stk.empty() && stk.top().second <= killed) {
      stk.pop();
    }
    stk.push({curr_psycho, killed});
  }
  cout << ans + 1 << endl;
}
