#include <bits/stdc++.h>
using namespace std;
const long long int maxN = 1e5 + 10;
long long int n, i, a[maxN], mx, cnt, nxt;
stack<pair<long long int, long long int> > st;
int main() {
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = n - 1; i >= 0; i--) {
    while (!st.empty()) {
      if (a[i] < st.top().first) break;
      cnt++;
      cnt = max(cnt, st.top().second);
      st.pop();
    }
    mx = max(mx, cnt);
    st.push(make_pair(a[i], cnt));
    cnt = 0;
  }
  cout << mx << endl;
}
