#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int a[N];
set<pair<int, int>> toKill, toKillNxt;
set<pair<int, int>> alive;
set<int> killed;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  a[n] = 1e9;
  int t = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) toKill.insert({i, i + 1});
  }
  for (int i = 0; i < n; i++) alive.insert({i, a[i]});
  while (toKill.size()) {
    for (auto p : toKill) {
      alive.erase({p.second, a[p.second]});
      killed.insert(p.second);
      auto it = alive.lower_bound({p.second, 0});
      if (it == alive.end()) continue;
      if (it->second > a[p.first]) continue;
      toKillNxt.insert({p.first, it->first});
    }
    toKill.clear();
    for (auto x : toKillNxt) {
      if (killed.count(x.first)) continue;
      if (killed.count(x.second)) {
        auto it = alive.lower_bound({x.second, 0});
        if (it == alive.end()) continue;
        if (it->second > a[x.first]) continue;
        toKill.insert({x.first, it->first});
        continue;
      }
      toKill.insert(x);
    }
    toKillNxt.clear();
    t++;
  }
  cout << t << endl;
  return 0;
}
