#include <bits/stdc++.h>
using namespace std;
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;
}
const int maxn = 100010;
int a[maxn];
int num[maxn];
int st[maxn];
int c;
int ans;
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  for (int i = n; i > 0; i--) {
    while (c && num[a[c - 1]] < num[i]) {
      st[i] = max(st[i] + 1, st[a[--c]]);
    }
    a[c] = i;
    c++;
    ans = max(ans, st[i]);
  }
  cout << ans << endl;
  return 0;
}
