#include <bits/stdc++.h>
using namespace std;
int n, ans, top;
int a[100010], b[100010], st[100010];
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = 0;
  }
  a[0] = 0;
  for (top = 0, i = n; i >= 1; i--) {
    while (top && a[i] > a[st[top - 1]]) {
      b[i]++;
      if (b[i] < b[st[top - 1]]) b[i] = b[st[top - 1]];
      top--;
    }
    st[top++] = i;
  }
  ans = b[1];
  for (i = 2; i <= n; i++) {
    if (ans < b[i]) ans = b[i];
  }
  printf("%d\n", ans);
  return 0;
}
