#include <bits/stdc++.h>
using namespace std;
int a[100010];
int ans, n;
struct aa {
  int x, eat;
} que[100010];
int main() {
  int tail = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int i = 1;
  while (a[i - 1] < a[i] && i < n) i++;
  que[tail].x = a[i - 1], que[tail++].eat = 0;
  for (; i < n; i++) {
    if (a[i] < que[tail - 1].x) {
      que[tail].x = a[i], que[tail++].eat = 1;
      ans = max(ans, 1);
      continue;
    }
    int ma = 0;
    while (tail > 0 && a[i] > que[tail - 1].x)
      ma = max(ma, que[tail - 1].eat), tail--;
    if (tail == 0)
      que[tail].eat = 0;
    else
      que[tail].eat = ma + 1;
    que[tail++].x = a[i];
    ans = max(ans, que[tail - 1].eat);
  }
  cout << ans << endl;
  return 0;
}
