#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const int N = 100005;
int n, a[N], pre[N], c[N], ans = 0;
int main() {
  scanf("%d", &n);
  a[0] = -1;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > mx) {
      c[i] = 0;
      pre[i] = 0;
    } else if (a[i] < a[i - 1]) {
      c[i] = 1;
      pre[i] = i - 1;
      ans = max(ans, 1);
    } else {
      int p = i - 1;
      while (a[i] > a[p] && p) {
        p = pre[p];
      }
      pre[i] = p;
      if (a[i] < a[pre[i - 1]])
        c[i] = c[i - 1] + 1;
      else {
        p = i - 1;
        int cnt = c[p];
        while (a[pre[p]] < a[i] && p) {
          p = pre[p];
          cnt = max(cnt, c[p]);
        }
        if (cnt) c[i] = cnt + 1;
      }
      ans = max(ans, c[i]);
    }
    mx = max(mx, a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
