#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, ans, a[N], q[N], f[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int t = 0;
  for (int i = n; i; i--) {
    q[++t] = a[i];
    while (t - 1 && q[t] > q[t - 1]) {
      if (f[q[t - 1]] > f[q[t]])
        f[q[t]] = f[q[t - 1]];
      else
        f[q[t]]++;
      q[t - 1] = q[t--];
    }
    ans = max(ans, f[q[t]]);
  }
  cout << ans << endl;
}
