#include <bits/stdc++.h>
using namespace std;
inline long long msb(long long val) { return 63 - __builtin_clzll(val); }
inline int msb(int val) { return 31 - __builtin_clz(val); }
template <class T>
bool chmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool chmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
const long long mod = 1e9 + 7, N = 2e5 + 5;
long long a[N], n, m, k;
long long p[N];
bool dead[N];
long long find_par(long long u) {
  if (p[u] == u) return u;
  return p[u] = find_par(p[u]);
}
void solve(long long test_case) {
  long long i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 0; i <= n + 2; i++) p[i] = i;
  vector<long long> pos;
  set<long long> tocheck;
  for (i = 2; i <= n; i++) {
    if (a[i - 1] > a[i]) {
      tocheck.insert(i - 1);
      pos.push_back(i);
    }
  }
  dead[n + 1] = true;
  long long ans = 0;
  while (pos.size()) {
    ans++;
    for (auto x : pos) {
      dead[x] = true;
      p[x] = find_par(x + 1);
    }
    vector<long long> t;
    vector<long long> toerase;
    for (auto x : tocheck) {
      long long xx = find_par(x + 1);
      if (!dead[xx] && a[x] > a[xx])
        t.push_back(xx);
      else
        toerase.push_back(x);
    }
    for (auto x : toerase) tocheck.erase(x);
    pos = t;
  }
  cout << ans << '\n';
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve(1);
  return 0;
}
