#include <bits/stdc++.h>
using namespace std;
long long a[1000008], pre[1000008], l[1000008], r[1000008];
long long s[1000008], top = 0;
long long ans, n;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = n; i >= 1; i--) {
    s[++top] = a[i];
    while ((top > 1) && s[top] > s[top - 1]) {
      if (pre[s[top - 1]] > pre[s[top]]) {
        pre[s[top]] = pre[s[top - 1]];
      } else
        pre[s[top]]++;
      s[top - 1] = s[top];
      top--;
    }
    ans = max(ans, pre[s[top]]);
  }
  printf("%lld", ans);
}
