#include <bits/stdc++.h>
using namespace std;
stack<int> s;
const int mXn = 100 * 1000 + 10;
int a[mXn], t[mXn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  t[0] = -1;
  for (int i = 0; i < n; i++) {
    int mx = 0;
    while ((int)s.size() && a[i] > a[s.top()]) {
      mx = max(mx, t[s.top()]);
      s.pop();
    }
    if (!(int)s.size())
      t[i] = -1;
    else
      t[i] = mx + 1;
    s.push(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, t[i]);
  }
  cout << ans;
  return 0;
}
