#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], dp[N];
stack<int> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int cnt = 0;
    while (st.size() && a[i] > a[st.top()])
      cnt += max(1, dp[st.top()] - cnt), st.pop();
    st.push(i);
    dp[i] = cnt;
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}
