#include <bits/stdc++.h>
using namespace std;
int N, M;
int ans, p[100005];
int stk[100005], stp[100005], top;
int main() {
  int i, j;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d", &p[i]);
  for (i = 1; i <= N; i++) {
    if (i == 1 || p[i] > stk[1]) {
      top = 0;
      ans = max(ans, stp[1]);
      stk[++top] = p[i], stp[top] = 0;
      continue;
    }
    for (top; stk[top] < p[i]; top--)
      ;
    stp[top]++;
    if (top > 1 && stp[top] == stp[top - 1]) top--;
    stk[++top] = p[i], stp[top] = 0;
  }
  ans = max(ans, stp[1]);
  printf("%d\n", ans);
  return 0;
}
