#include <bits/stdc++.h>
using namespace std;
long long a[100005], f[100005], st[100005], top;
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 << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
signed main() {
  long long n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long mx = 0;
    while (top && a[st[top]] < a[i]) mx = max(mx, f[st[top--]]);
    if (top == 0) {
      f[i] = 0;
    } else {
      f[i] = mx + 1;
    }
    st[++top] = i;
    ans = max(ans, f[i]);
  }
  cout << ans << endl;
  return 0;
}
