#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
int n;
int a[N];
int t[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i] = -a[i];
  }
  int ans = 0;
  stack<pair<int, int> > second;
  for (int i = 1; i <= n; i++) {
    int cmax = 0;
    while (!second.empty() && second.top().first > a[i]) {
      cmax = max(cmax, second.top().second);
      second.pop();
    }
    if (second.empty()) {
      second.push(make_pair(a[i], n + 1));
    } else {
      second.push(make_pair(a[i], cmax + 1));
      ans = max(ans, cmax + 1);
    }
  }
  printf("%d", ans);
  return 0;
}
