#include <bits/stdc++.h>
using namespace std;
const int maxN = 101000;
int n;
int a[maxN];
int who[maxN];
int steps[maxN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  who[0] = 0;
  steps[0] = 0;
  int mx = a[0];
  for (int i = 1; i < n; ++i) {
    if (mx < a[i]) {
      who[i] = steps[i] = 0;
      mx = max(mx, a[i]);
      continue;
    }
    int cur = i - 1;
    who[i] = 0;
    steps[i] = 0;
    while (true) {
      if (a[cur] > a[i]) {
        who[i] = cur;
        ++steps[i];
        break;
      } else {
        steps[i] = max(steps[i], steps[cur]);
        cur = who[cur];
      }
    }
    mx = max(mx, a[i]);
  }
  cout << *max_element(steps, steps + n) << endl;
  return 0;
}
