#include <bits/stdc++.h>
using namespace std;
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
inline int gcd(int a, int b) {
  if (a % b)
    return gcd(b, a % b);
  else
    return b;
}
inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
inline int And(int mask, int bit) { return mask & (1 << bit); }
inline int Or(int mask, int bit) { return mask | (1 << bit); }
inline int Xor(int mask, int bit) { return mask & (~(1 << bit)); }
int lf[100100], rt[100100], a[100100], mark[100100];
int n, k, x, res, f;
vector<int> q[2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mark[i] = 0;
    lf[i] = i - 1;
    rt[i] = i + 1;
  }
  lf[n + 1] = n;
  rt[n] = n + 1;
  a[n + 1] = n + 1;
  for (int i = n - 1; i >= 1; i--)
    if (a[i] > a[i + 1]) q[0].push_back(i), mark[i + 1] = 1;
  f = res = 0;
  while (!q[f].empty()) {
    res++;
    q[f ^ 1].clear();
    for (int i = 0; i < q[f].size(); i++) {
      k = q[f][i];
      x = rt[rt[k]];
      rt[k] = x;
      lf[x] = k;
      if (a[k] > a[x] && !mark[k]) q[f ^ 1].push_back(k), mark[x] = 1;
    }
    f ^= 1;
  }
  printf("%d\n", res);
  return 0;
}
