#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
typedef int typev;
struct BIT {
  typev ar[N];
  int n;
  void init(int nn) {
    memset(ar, 0, sizeof(ar));
    n = nn + 1;
  }
  void add(int i, typev v) {
    for (; i < n; ar[i] += v, i += ((i) & (-i)))
      ;
  }
  typev sum(int i) {
    typev s = 0;
    for (; i > 0; s += ar[i], i -= ((i) & (-i)))
      ;
    return s;
  }
  typev sum(int x, int y) { return (sum(y) - sum(x - 1)); }
  typev lower_bound(typev x) {
    int i = 20, ret = 0;
    typev s = 0;
    for (; i >= 0; i--) {
      ret ^= 1 << i;
      if (ret >= n || ar[ret] + s >= x)
        ret ^= 1 << i;
      else
        s += ar[ret];
    }
    return ret + 1;
  }
} s;
int a[N], pos[N], f[N], head, rear, n, next[N], q[N];
int solve() {
  int ret = 0, flag = 1, x, y, i;
  for (ret = 0; flag && head; ret++) {
    flag = 0;
    for (i = head - 1; i >= 0; i--) {
      x = q[i];
      y = s.lower_bound(s.sum(x) + 1);
      if (a[x] > a[y] && y <= n) {
        f[y] = 1;
        s.add(y, -1);
        flag = 1;
      }
    }
    for (i = 0, rear = 0; i < head; i++) {
      if (f[q[i]] == 0) q[rear++] = q[i];
    }
    if (flag == 0) return ret;
    head = rear;
  }
  return ret;
}
int main() {
  int i, j, x;
  scanf("%d", &n);
  s.init(n);
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  for (i = 1; i <= n + 1; i++) {
    if (a[i] > a[i + 1] && i < n) q[head++] = i;
    s.add(i, 1);
  }
  printf("%d\n", solve());
  return 0;
}
