#include <bits/stdc++.h>
using namespace std;
int a[100005], t[100005];
int main() {
  int i, j, n, m, ans, sum;
  stack<int> s;
  scanf("%d", &n);
  ;
  for (i = 0; i < n; i++) cin >> a[i];
  s.push(0);
  t[0] = -1;
  ans = 0;
  for (i = 1; i < n; i++) {
    t[i] = 0;
    while (!s.empty() && a[s.top()] < a[i]) {
      t[i] = max(t[i], t[s.top()] + 1);
      s.pop();
    }
    if (s.empty()) t[i] = -1;
    s.push(i);
    ans = max(ans, t[i] + 1);
  }
  cout << ans;
  return 0;
}
