#include <bits/stdc++.h>
using namespace std;
int a[200000];
int q[200000][3];
int main() {
  int i, j, n, ans, tmp, m;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  ans = 0;
  q[0][0] = a[0];
  q[0][1] = 0;
  q[0][2] = 2000000;
  m = 1;
  ans = 0;
  for (i = 1; i < n; i++) {
    while ((m > 0) && (a[i] > q[m - 1][0])) m--;
    if (m == 0) {
      q[m][0] = a[i];
      q[m][1] = 0;
      q[m][2] = 2000000;
      m++;
    } else {
      q[m - 1][1]++;
      if (q[m - 1][1] > ans) ans = q[m - 1][1];
      tmp = q[m - 1][1];
      while ((m > 0) && (q[m - 1][1] == q[m - 1][2])) {
        m--;
      }
      q[m][0] = a[i];
      q[m][1] = 0;
      q[m][2] = tmp;
      m++;
    }
  }
  printf("%d\n", ans);
}
