#include <bits/stdc++.h>
using namespace std;
int N, A[100010];
int G[100010];
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  stack<int> st;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    while (st.empty() == false and A[st.top()] <= A[i]) {
      G[i] = max(G[i], G[st.top()] + 1);
      st.pop();
    }
    if (st.empty()) {
      G[i] = -1;
    }
    ans = max(ans, G[i] + 1);
    st.push(i);
  }
  cout << ans << '\n';
  return 0;
}
