#include <bits/stdc++.h>
using namespace std;
stack<pair<int, int> > q;
int num[100005], n;
int main() {
  cin >> n;
  int Max = 0;
  for (int i = 0; i < n; i++) cin >> num[i];
  q.push(make_pair(num[n - 1], 0));
  for (int i = n - 2; i >= 0; i--) {
    int ct = 0;
    while (!q.empty() && num[i] > (q.top()).first) {
      if (q.top().second > ct)
        ct = q.top().second;
      else
        ct++;
      q.pop();
    }
    Max = max(Max, ct);
    q.push(make_pair(num[i], ct));
  }
  cout << Max << endl;
  return 0;
}
