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