#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  list<int> l;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    l.push_back(x);
  }
  list<list<int>::iterator> killers;
  for (auto it = l.begin(); it != prev(l.end()); ++it) {
    if (*it > *next(it) && (it == l.begin() || *it > *prev(it)))
      killers.push_back(it);
  }
  int steps = 0;
  bool killed = true;
  while (killed) {
    killed = false;
    for (auto it = killers.begin(); it != killers.end();) {
      int prv = **it;
      while (next(*it) != l.end() && prv > *next(*it)) {
        prv = *next(*it);
        l.erase(next(*it));
        killed = true;
      }
      if (it != killers.begin() && *prev(*it) > **it)
        it = killers.erase(it);
      else
        ++it;
    }
    ++steps;
  };
  cout << steps - 1 << endl;
  return 0;
}
