#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  stack<pair<int, int> > s;
  int ans = 0;
  s.push(make_pair(arr[n - 1], 0));
  for (int i = n - 2; i >= 0; i--) {
    if (s.top().first > arr[i])
      s.push(make_pair(arr[i], 0));
    else {
      int res = 0;
      while (!s.empty() and s.top().first < arr[i]) {
        res = max(res + 1, s.top().second);
        s.pop();
      }
      s.push(make_pair(arr[i], res));
    }
  }
  while (!s.empty()) {
    ans = max(ans, s.top().second);
    s.pop();
  }
  cout << ans << "\n";
  return 0;
}
