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