#include <bits/stdc++.h>
using namespace std;
int n, q, p, p1, maxi, a[1000000], idx;
stack<int> t, t1, id;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  maxi = -1;
  id.push(0);
  t.push(200000);
  t1.push(-1);
  for (int i = 1; i < n; i++) {
    p = 0;
    q = 5;
    while (q == 5) {
      idx = id.top();
      p1 = t.top();
      p = t1.top() + 1;
      if (a[idx] > a[i] && p <= p1) {
        q = 6;
        t1.top() = p;
        if (p > maxi) maxi = p;
        id.push(i);
        t.push(p);
        t1.push(-1);
      } else if (p1 == 200000) {
        q = 7;
        id.push(i);
        t.push(200000);
        t1.push(-1);
      } else {
        id.pop();
        t.pop();
        t1.pop();
      }
    }
  }
  printf("%d", maxi + 1);
  return 0;
}
