#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
int ar[Max];
int main() {
  int n;
  scanf("%d", &n);
  set<int> st, alive;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (i > 1) {
      if (ar[i] < ar[i - 1]) {
        st.insert(i);
      }
    }
    alive.insert(i);
  }
  int ans = 0;
  while (st.size()) {
    ans += 1;
    set<int> cur;
    for (int x : st) {
      int del = x;
      alive.erase(del);
    }
    for (int x : st) {
      auto Lf = alive.lower_bound(x);
      auto Rt = Lf;
      Lf--;
      if (alive.find(*Lf) != alive.end() && alive.find(*Rt) != alive.end() &&
          *Lf < *Rt) {
        if (ar[*Lf] > ar[*Rt]) {
          cur.insert(*Lf);
          cur.insert(*Rt);
        }
      }
    }
    st.clear();
    int prv = -1;
    for (int x : cur) {
      if (prv != -1) {
        if (ar[x] < ar[prv]) {
          st.insert(x);
        }
      }
      prv = x;
    }
  }
  printf("%d\n", ans);
  return 0;
}
