#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  stack<pair<long long int, long long int> > s;
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    long long int crt = 0;
    while (s.size() && (s.top()).first < a[i]) {
      crt++;
      crt = max(crt, (s.top()).second);
      s.pop();
    }
    ans = max(ans, crt);
    s.push({a[i], crt});
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
