#include <bits/stdc++.h>
using namespace std;
stack<int> s;
stack<int> ajal;
int main() {
  int n, a, ans = 0;
  cin >> n >> a;
  s.push(a);
  ajal.push(0);
  for (int i = 1; i < n; i++) {
    cin >> a;
    int m = 0;
    while ((!ajal.empty()) && s.top() <= a && ajal.top() > -1) {
      m = max(ajal.top(), m);
      ajal.pop();
      s.pop();
    }
    if (ajal.empty() || s.top() < a) m = -2;
    ajal.push(m + 1);
    s.push(a);
    ans = max(ans, m + 1);
  }
  cout << ans << endl;
  return 0;
}
