#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, ans = 0;
long long a[N];
stack<pair<long long, long long> > s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  reverse(a + 1, a + n + 1);
  for (long long i = 1; i <= n; i++) {
    long long cur = 0, store = 0;
    while (s.size() && s.top().first < a[i]) {
      cur++;
      cur = max(cur, s.top().second);
      s.pop();
    }
    ans = max(ans, cur);
    s.push({a[i], cur});
  }
  cout << ans;
  return 0;
}
