#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
int h[MAXN], s[MAXN];
int n, stp[MAXN] = {};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
  int tp = 0;
  for (int i = n; i >= 1; i--) {
    s[++tp] = h[i];
    stp[tp] = 0;
    while (tp > 1 && s[tp] > s[tp - 1]) {
      int nstp = 0;
      if (stp[tp] >= stp[tp - 1])
        nstp = stp[tp] + 1;
      else
        nstp = stp[tp - 1];
      stp[tp - 1] = nstp, s[tp - 1] = s[tp];
      tp--;
    }
  }
  int ans = 0;
  for (int i = 1; i <= tp; i++)
    if (stp[i] > ans) ans = stp[i];
  printf("%d\n", ans);
  return 0;
}
