#include <bits/stdc++.h>
int a[100005];
int killer[100005];
int step[100005];
int main(void) {
  int n;
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  killer[1] = 0;
  step[1] = 0;
  for (i = 2; i <= n; i++) {
    int ts = 0;
    int safe = 0;
    j = i - 1;
    while (a[i] > a[j] && j > 0) {
      if (step[j] == 0) {
        safe = 1;
        break;
      }
      if (ts < step[j]) ts = step[j];
      j = killer[j];
    }
    if (safe == 1)
      step[i] = 0;
    else
      step[i] = ts + 1;
    killer[i] = j;
  }
  int ans = 0;
  for (i = 1; i <= n; i++)
    if (ans < step[i]) ans = step[i];
  printf("%d\n", ans);
  return 0;
}
