#include <bits/stdc++.h>
using namespace std;
int a[100010], q[100010], d[100010];
int main() {
  int n, i, ans = 0, cnt = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 1; i <= n; ++i) {
    if (a[i] > a[i - 1]) {
      for (; cnt && a[i] > a[q[cnt - 1]]; --cnt)
        d[i] = max(d[q[cnt - 1]] + 1, d[i]);
      if (cnt == 0)
        d[i] = 0;
      else
        d[i] = max(d[i], 2);
      q[cnt++] = i;
    } else
      d[i] = 1;
    ans = max(ans, d[i]);
  }
  printf("%d\n", ans);
  return 0;
}
