#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }
int a[maxn], n;
int nxt[maxn];
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    nxt[i] = i + 1;
  }
  nxt[n] = -1;
  queue<int> q;
  for (int i = n - 1; i >= 1; i--) {
    if (a[i] > a[i + 1]) {
      q.emplace(i);
    }
  }
  long long ans = 0;
  while (!q.empty()) {
    ans++;
    int sz = q.size();
    for (int i = 0; i < sz; i++) {
      int x = q.front();
      q.pop();
      nxt[x] = nxt[nxt[x]];
      if (nxt[x] != -1 && a[x] > a[nxt[x]]) {
        q.emplace(x);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
