#include <bits/stdc++.h>
using namespace std;
int a[100005], f[100005], st[100005];
int main() {
  int n, top = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = n - 1; i >= 0; i--) {
    int t = 0;
    while (top && a[st[top - 1]] < a[i]) f[i] = t = max(t + 1, f[st[--top]]);
    st[top++] = i;
  }
  printf("%d\n", *max_element(f, f + n));
}
