#include <bits/stdc++.h>
using namespace std;
int num[100100], nxt[100100];
int dead[100100];
queue<int> q[2];
int main() {
  int now = 0;
  int ans = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> num[i];
    nxt[i] = i + 1;
  }
  num[n] = 1 << 30;
  for (int i = 0; i < n; ++i) {
    if (num[i] > num[i + 1]) {
      q[now].push(i);
    }
  }
  while (!q[now].empty()) {
    ans++;
    int last = now;
    now = 1 - now;
    while (!q[now].empty()) {
      q[now].pop();
    }
    while (!q[last].empty()) {
      int v = q[last].front();
      q[last].pop();
      if (dead[v]) {
        continue;
      }
      int p = v;
      while (num[p] > num[nxt[p]]) {
        dead[nxt[p]] = 1;
        p = nxt[p];
      }
      if (num[v] > num[p] && !dead[v]) {
        nxt[v] = nxt[p];
        q[now].push(v);
      }
    }
  }
  if (ans >= 1) {
    ans--;
  }
  cout << ans << endl;
  return 0;
}
