#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
struct node {
  int u, v;
  node(int x, int y) : u(x), v(y) {}
};
stack<node> s;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  int index;
  int ci, okk;
  ci = 0;
  for (int i = 0; i <= n - 1; i++) {
    index = a[i];
    okk = 0;
    while (!s.empty() && s.top().u < index) {
      ci = max(ci, s.top().v);
      s.pop();
      okk = 1;
    }
    ci = ci + 1;
    if (okk == 0) {
      ci = 1;
    }
    if (s.empty()) ci = 0;
    s.push(node(index, ci));
    b[i] = ci;
  }
  int sum = 0;
  for (int i = 0; i <= n - 1; i++) sum = max(sum, b[i]);
  cout << sum << endl;
  return 0;
}
