#include <bits/stdc++.h>
using namespace std;
stack<int> S;
int a[100010];
int f[100010];
int res = 0;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i >= 1; i--) {
    while ((S.size() != 0) && (a[i] > a[S.top()])) {
      f[i] = max(f[i] + 1, f[S.top()]);
      S.pop();
    }
    S.push(i);
    res = max(res, f[i]);
  }
  cout << res;
  return 0;
}
