#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int N;
int sol[MAXN];
int ar[MAXN];
int seg[MAXN * 3];
int upd(int konum, int bas, int son, int pl, int t) {
  if (bas > pl || son < pl) return seg[konum];
  if (bas == son) return seg[konum] = t;
  return seg[konum] =
             max(upd(konum * 2, bas, ((bas + son) / 2), pl, t),
                 upd(konum * 2 + 1, ((bas + son) / 2) + 1, son, pl, t));
}
int find(int konum, int bas, int son, int a1, int a2) {
  if (bas > a2 || son < a1) return 0;
  if (bas >= a1 && son <= a2) return seg[konum];
  return max(find(konum * 2, bas, ((bas + son) / 2), a1, a2),
             find(konum * 2 + 1, ((bas + son) / 2) + 1, son, a1, a2));
}
int main() {
  scanf(" %d", &N);
  for (int i = 1; i <= N; i++) scanf(" %d", &ar[i]);
  for (int i = 1; i <= N; i++) {
    sol[i] = i - 1;
    while (ar[sol[i]] < ar[i] && sol[i]) sol[i] = sol[sol[i]];
    if (sol[i] == 0) continue;
    upd(1, 1, N, i, find(1, 1, N, sol[i] + 1, i) + 1);
  }
  printf("%d\n", seg[1]);
  return 0;
}
