#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch <= '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int num[maxn], ans[maxn];
int n;
stack<int> s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  for (int i = n; i >= 1; i--) {
    if (s.empty()) {
      s.push(num[i]);
      ans[i] = 0;
      continue;
    }
    if (s.top() > num[i]) {
      s.push(num[i]);
      ans[num[i]] = 0;
    } else if (s.top() <= num[i]) {
      int temp = max(1, ans[s.top()]);
      s.pop();
      while (!s.empty() && s.top() <= num[i]) {
        temp = max(temp + 1, ans[s.top()]);
        s.pop();
      }
      ans[num[i]] = temp;
      s.push(num[i]);
    }
  }
  int maxx = 0;
  for (int i = 1; i <= n; i++) {
    maxx = max(maxx, ans[i]);
  }
  printf("%d\n", maxx);
}
