#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[1000005];
int f[1000005];
int t[1000005];
int main() {
  int n = read(), top = 0, ans = 0;
  for (int i = 0; i < n; i++) a[i] = read();
  for (int i = n - 1; i >= 0; i--) {
    int tt = 0;
    while (top && a[t[top - 1]] < a[i]) f[i] = tt = max(tt + 1, f[t[--top]]);
    t[top++] = i;
  }
  printf("%d", *max_element(f, f + n));
}
