#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, ans, cnt;
int a[100005], head[100005], pre[100005], f[100005];
bool used[100005], flag;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(f, 0, sizeof f);
  ans = 0;
  a[0] = 0;
  head[0] = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] > a[i - 1]) {
      head[i] = i;
      pre[i] = head[i - 1];
      k = pre[i];
      cnt = 0;
      flag = false;
      used[i] = true;
      while (k) {
        if (a[k] > a[i]) {
          cnt++;
          flag = true;
          break;
        }
        if (used[k] == false) break;
        cnt = max(cnt, f[k]);
        k = pre[k];
      }
      if (!flag) {
        used[i] = false;
        f[i] = 0;
      } else {
        f[i] = cnt;
        pre[i] = k;
        ans = max(ans, f[i] + 1);
      }
    } else {
      head[i] = head[i - 1];
      f[i] = 0;
      ans = max(ans, 1);
    }
  }
  printf("%d\n", ans);
  return 0;
}
