#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int x[N];
struct node {
  int num, val;
} now;
stack<node> s;
int main() {
  int n, i, ans = 0, k, w;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (i = 1; i <= n; i++) {
    k = 0;
    while (!s.empty()) {
      now = s.top();
      if (now.num < x[i]) {
        s.pop();
        k = max(k, now.val);
      } else
        break;
    }
    now.num = x[i];
    now.val = k + 1;
    if (s.empty()) now.val = 0;
    ans = max(ans, now.val);
    s.push(now);
  }
  printf("%d", ans);
}
