#include <bits/stdc++.h>
using namespace std;
int a[100010], n, q[100010], res[100010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int t = 0;
  int resmax = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (t && a[q[t]] < a[i]) res[i] = max(res[i] + 1, res[q[t--]]);
    q[++t] = i;
    resmax = max(resmax, res[i]);
  }
  cout << resmax;
}
