#include <bits/stdc++.h>
using namespace std;
int n, st[(100000 + 10)], size = 0, a[(100000 + 10)], f[(100000 + 10)] = {0};
int main() {
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i; i--) {
    int t = 0;
    while (size && a[st[size]] < a[i]) {
      t++;
      f[i] = t = max(t, f[st[size]]);
      size--;
    }
    st[++size] = i;
    ans = max(ans, t);
  }
  cout << ans << endl;
  return 0;
}
