#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> all(n);
  for (int i = 0; i < n; i++) cin >> all[i];
  vector<int> f(n, 0);
  deque<int> q;
  q.push_back(n - 1);
  int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (all[i] < all[q[q.size() - 1]]) {
      q.push_back(i);
      continue;
    }
    int cnt = 0;
    while (q.size() && all[i] > all[q[q.size() - 1]]) {
      f[i] += max(1, f[q[q.size() - 1]] - cnt);
      cnt += max(1, f[q[q.size() - 1]] - cnt);
      q.pop_back();
    }
    q.push_back(i);
    ans = max(f[i], ans);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t > 0) {
    t--;
    solve();
  }
}
