#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
using VL = vector<LL>;
using VI = vector<int>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using PII = pair<int, int>;
void _print() {}
template <typename T, typename... Args>
void _print(const T first_elem, const Args... args) {}
int main() {
  ios::sync_with_stdio(false);
  LL n;
  cin >> n;
  VL a(n), times(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  times[0] = -1;
  LL ans = 0;
  stack<LL> st;
  st.push(0);
  for (int i = 1; i < n; i++) {
    times[i] = 0;
    while (st.size() && a[i] > a[st.top()]) {
      times[i] = max(times[i], times[st.top()] + 1);
      st.pop();
    }
    if (st.size() == 0) {
      times[i] = -1;
    }
    st.push(i);
    ans = max(ans, times[i] + 1);
  }
  cout << ans << endl;
  return 0;
}
