#include <bits/stdc++.h>
using namespace std;
int const N = 100005;
struct TREE {
  int dp[N << 2];
  inline void pushUp(int rt) { dp[rt] = max(dp[(rt << 1)], dp[(rt << 1 | 1)]); }
  void update(int p, int v, int l = 1, int r = N, int rt = 1) {
    if (l == r) {
      dp[rt] = v;
      return;
    }
    int m = (l + r) >> 1;
    if (p <= m)
      update(p, v, l, m, (rt << 1));
    else
      update(p, v, m + 1, r, (rt << 1 | 1));
    pushUp(rt);
  }
  int query(int L, int R, int l = 1, int r = N, int rt = 1) {
    if (L <= l && R >= r) return dp[rt];
    int m = (l + r) >> 1, lv, rv;
    if (m >= R)
      return query(L, R, l, m, (rt << 1));
    else if (L > m)
      return query(L, R, m + 1, r, (rt << 1 | 1));
    lv = query(L, R, l, m, (rt << 1));
    rv = query(L, R, m + 1, r, (rt << 1 | 1));
    return max(lv, rv);
  }
} ta, tb;
int main() {
  int n, i;
  int vec[N];
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &vec[i]);
  }
  tb.update(vec[1], 1);
  for (i = 2; i <= n; i++) {
    if (vec[i] < vec[i - 1])
      ta.update(i, 1);
    else {
      int j = tb.query(vec[i], n);
      if (j != 0) ta.update(i, ta.query(j + 1, i - 1) + 1);
    }
    tb.update(vec[i], i);
  }
  printf("%d\n", ta.dp[1]);
  return 0;
}
