#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int days[N], heights[N];
  stack<int> Stack;
  for (int i = 0; i < N; i++) cin >> heights[i];
  days[0] = -1;
  Stack.push(0);
  int MAX = -1;
  for (int i = 1; i < N; i++) {
    days[i] = 1;
    while (!Stack.empty() && heights[i] > heights[Stack.top()]) {
      if (days[Stack.top()] + 1 > days[i]) days[i] = days[Stack.top()] + 1;
      Stack.pop();
    }
    if (Stack.empty()) days[i] = -1;
    MAX = max(days[i], MAX);
    Stack.push(i);
  }
  cout << max(MAX, 0) << endl;
  return 0;
}
