#include <bits/stdc++.h>
using namespace std;
int tdeath[100005], A[100005];
vector<int> st;
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 0; i < n; i++) {
    while (st.size() && A[st.back()] < A[i]) {
      tdeath[i] = max(tdeath[i], tdeath[st.back()] + 1);
      st.pop_back();
    }
    if (st.size() == 0) tdeath[i] = -1;
    ans = max(tdeath[i] + 1, ans);
    st.push_back(i);
  }
  cout << ans << endl;
  return 0;
}
