#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> next(n, -1);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  for (int i = 0; i < (int)(n - 1); i++) next[i] = i + 1;
  queue<int> q;
  for (int i = n - 2; i >= 0; i--) q.push(i);
  int ans = 0;
  vector<bool> dead(n, false);
  for (;;) {
    vector<int> kill;
    vector<int> can;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      if (next[v] != -1 && a[next[v]] < a[v]) {
        can.push_back(v);
        kill.push_back(next[v]);
        dead[next[v]] = true;
        next[v] = next[next[v]];
      }
    }
    if ((int)kill.size() == 0) break;
    ans++;
    for (int i = 0; i < (int)((int)can.size()); i++)
      if (!dead[can[i]]) q.push(can[i]);
  }
  cout << ans;
}
