#include <bits/stdc++.h>
using namespace std;
int b, n, a, t, j, e[100005], c, m, i, d[100005], k;
stack<int> s;
int main() {
  cin >> n;
  for (i = 0; i <= n; i++) {
    cin >> e[i];
    d[e[i]] = 1;
    while (s.size() > 0 && s.top() < e[i]) {
      d[e[i]] = max(d[e[i]], d[s.top()] + 1);
      k = max(k, d[i]);
      s.pop();
    }
    if (s.size() == 0) d[e[i]] = 0;
    s.push(e[i]);
  }
  for (int i = 1; i <= n; i++) k = max(k, d[i]);
  cout << k << endl;
}
