#include <bits/stdc++.h>
using namespace std;
int n, num[100010], mystack[100010], stot, record[100010];
void Init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
}
void solve() {
  for (int i = 1; i <= n; i++) {
    while (stot > 0 && num[mystack[stot]] < num[i]) {
      record[i] = max(record[i], record[mystack[stot]]);
      stot--;
    }
    if (stot) record[i]++;
    mystack[++stot] = i;
  }
  int maxn = 0;
  for (int i = 1; i <= n; i++) maxn = max(maxn, record[i]);
  printf("%d\n", maxn);
}
int main() {
  Init();
  solve();
  return 0;
}
