#include <bits/stdc++.h>
using namespace std;
int a[100005], s[100005], f[100005];
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  s[1] = 0, f[1] = 0;
  for (int i = 2; i <= n; i++) {
    int step = 0, t = i - 1;
    while (a[t] < a[i] && t) {
      step = max(step, s[t]);
      t = f[t];
    }
    if (a[t] > a[i]) {
      f[i] = t;
      s[i] = step + 1;
    } else {
      f[i] = 0;
      s[i] = 0;
    }
    ans = max(ans, s[i]);
  }
  printf("%d\n", ans);
  return 0;
}
