#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec;
  set<int> st;
  for (int i = 0; i < int(n); ++i) {
    int a;
    cin >> a;
    st.insert(i);
    vec.push_back(a);
  }
  queue<int> tok;
  int ans = 0;
  int killed = 0;
  for (int i = n - 1; i > 0; i--) {
    if (vec[i] < vec[i - 1]) {
      st.erase(i);
      ++killed;
      tok.push(i - 1);
    }
  }
  if (killed) ans++;
  queue<int> qtok;
  while (killed) {
    killed = 0;
    while (!tok.empty()) {
      int tp = tok.front();
      tok.pop();
      auto it = st.find(tp);
      if (it == st.end()) continue;
      auto itn = st.find(tp);
      itn++;
      if (itn == st.end()) continue;
      if (vec[*it] > vec[*itn]) {
        qtok.push(*it);
        ++killed;
        st.erase(itn);
      }
    }
    while (!qtok.empty()) {
      tok.push(qtok.front());
      qtok.pop();
    }
    if (killed) ans++;
  }
  cout << ans << endl;
  return 0;
}
