#include <bits/stdc++.h>
using namespace std;
int n, sol, x, act;
list<int> l;
list<int>::iterator it, it2;
vector<list<int>::iterator> v[2];
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    l.push_back(x);
  }
  it = l.begin();
  it++;
  for (it; it != l.end(); it++) {
    it2 = it;
    it2--;
    if ((*it2) > (*it)) v[0].push_back(it);
  }
  while (v[act].size()) {
    sol++;
    for (i = 0; i < v[act].size(); i++) {
      it = v[act][i];
      it = l.erase(it);
      if (it == l.end() || (i + 1 < v[act].size() && it == v[act][i + 1]))
        continue;
      it2 = it;
      it2--;
      if ((*it2) > (*it)) v[1 - act].push_back(it);
    }
    v[act].clear();
    act = 1 - act;
  }
  cout << sol << '\n';
  return 0;
}
