#include <bits/stdc++.h>
using namespace std;
struct data {
  int num, step;
};
stack<data> S;
int a[100005], n;
int main() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", a + i);
  int answer = 0;
  data tmp;
  tmp.num = a[0];
  tmp.step = 2 * n;
  S.push(tmp);
  for (i = 1; i < n; i++) {
    data now;
    now.num = a[i];
    now.step = 0;
    while (1) {
      tmp = S.top();
      if (tmp.num > now.num) {
        if (tmp.step == now.step) S.pop();
        S.push(now);
        break;
      } else {
        S.pop();
        now.step = tmp.step + 1;
        if (tmp.step == 2 * n) {
          now.step = 2 * n;
          S.push(now);
          break;
        }
      }
    }
    if (now.step != 2 * n) answer = max(answer, now.step + 1);
  }
  printf("%d", answer);
  return 0;
}
