#include <bits/stdc++.h>
using namespace std;
int const inf = 1000000009;
int const maxn = 100005;
int tree[maxn * 4];
int sz = 1;
int get(int l, int r) {
  int ans = 0;
  for (l += sz, r += sz; l <= r; l = (l + 1) / 2, r = (r - 1) / 2) {
    if (l % 2 == 1 && tree[l] > ans) ans = tree[l];
    if (r % 2 == 0 && tree[r] > ans) ans = tree[r];
  }
  return ans;
}
void add(int ind, int x) {
  tree[ind += sz] = x;
  for (ind /= 2; ind > 0; ind /= 2)
    tree[ind] = max(tree[2 * ind], tree[2 * ind + 1]);
}
int ans[maxn];
int time_life[maxn];
int pre[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  while (sz <= n) sz *= 2;
  time_life[0] = inf;
  for (int i = 1; i <= n; ++i) {
    int cur;
    cin >> cur;
    int cur_pre = get(cur + 1, n);
    while (time_life[cur_pre] == ans[cur_pre]) {
      add(cur_pre, 0);
      cur_pre = pre[cur_pre];
    }
    ++ans[cur_pre];
    time_life[i] = cur_pre == 0 ? inf : ans[cur_pre];
    pre[i] = cur_pre;
    add(cur, i);
  }
  cout << (*max_element(ans + 1, ans + n + 1)) << endl;
  return 0;
}
