#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int main() {
  scanf("%d", &n);
  stack<int> killer;
  vector<int> pos(n), health(n, 1);
  health[0] = INT_MAX;
  killer.push(0);
  for (int i = 0; i < n; i++) scanf("%d", &pos[i]);
  for (int i = 1; i < n; i++) {
    while (pos[i] > pos[killer.top()] && killer.size() > 1) {
      if (health[killer.top()] != INT_MAX)
        health[i] = max(health[killer.top()] + 1, health[i]);
      killer.pop();
    }
    if (pos[i] > pos[killer.top()]) {
      killer.pop();
      health[i] = INT_MAX;
    }
    if (health[i] != INT_MAX) ans = max(health[i], ans);
    killer.push(i);
  }
  printf("%d\n", ans);
  return 0;
}
