#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, s, a[N], x[N];
stack<int> stk;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  stk.push(n - 1);
  for (int i = n - 2; i >= 0; i--) {
    x[i] = 0;
    while (!stk.empty() && a[stk.top()] < a[i]) {
      x[i] = x[i] + max(1, x[stk.top()] - x[i]);
      stk.pop();
    }
    stk.push(i);
  }
  for (int i = 0; i < n; i++) {
    s = max(s, x[i]);
  }
  cout << s << endl;
  return 0;
}
