#include <bits/stdc++.h>
using namespace std;
int n, ans, flag;
int a[100005], b[100005], xb[100005];
void solve() {
  int i, j, ma;
  ans = -1;
  b[1] = xb[1] = 0;
  for (i = 2; i <= n; i++) {
    ma = 0;
    flag = 0;
    j = i - 1;
    while (a[j] < a[i] && j) {
      if (!b[j]) {
        flag = 1;
        break;
      }
      if (b[j] > ma) ma = b[j];
      j = xb[j];
    }
    if (!flag)
      b[i] = ma + 1;
    else
      b[i] = 0;
    xb[i] = j;
  }
  for (i = 1; i <= n; i++) {
    if (ans < b[i]) ans = b[i];
  }
}
int main() {
  int i, j;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    solve();
    printf("%d\n", ans);
  }
  return 0;
}
