#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
int main(void) {
  int n;
  stack<int> s;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n; i >= 1; i--) {
    if (s.empty()) {
      s.push(a[i]);
      b[i] = 0;
      continue;
    }
    if (a[i] < s.top()) {
      s.push(a[i]);
      b[a[i]] = 0;
    } else if (a[i] > s.top()) {
      int temp = max(1, b[s.top()]);
      s.pop();
      while (!s.empty() && a[i] > s.top()) {
        temp = max(temp + 1, b[s.top()]);
        s.pop();
      }
      b[a[i]] = temp;
      s.push(a[i]);
    }
  }
  int k = 0;
  for (int i = 1; i <= n; i++) k = max(k, b[i]);
  printf("%d\n", k);
}
