#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010], res[100010], x[100010];
int main() {
  int n, i, j, k, m;
  int ans = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  m = 1;
  b[0] = a[0];
  x[a[0]] = 1000000;
  for (i = 1; i < n; i++) {
    x[a[i]] = 1000000;
    for (j = m - 1; j >= 0; j--) {
      if (b[j] > a[i] && x[b[j]] > res[j]) break;
    }
    if (j >= 0) {
      x[a[i]] = res[j] + 1;
      res[j]++;
      b[++j] = a[i];
      res[j] = 0;
      m = j + 1;
    } else {
      b[0] = a[i];
      res[0] = 0;
      m = 1;
    }
  }
  for (i = 1; i <= n; i++)
    if (x[i] < 1000000) ans = (ans > x[i] ? ans : x[i]);
  printf("%d\n", ans);
  return 0;
}
