#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, ans = 0;
  scanf("%lld", &n);
  vector<long long> a(n);
  stack<pair<long long, long long> > s;
  for (long long i = 0; i < n; i++) scanf("%lld", &a[i]);
  reverse(a.begin(), a.end());
  s.push({a[0], 0});
  for (long long i = 1; i < n; i++) {
    long long cnt = 0;
    while (!s.empty() && a[i] > s.top().first) {
      cnt++;
      cnt = max(cnt, s.top().second);
      s.pop();
    }
    s.push({a[i], cnt});
    ans = max(ans, cnt);
  }
  printf("%lld ", ans);
  return 0;
}
