#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void one();
int main() {
  fastio();
  int t = 1;
  for (int i = 0; i < t; ++i) {
    one();
  }
  return 0;
}
void one() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> par(n);
  vector<int> ch(n);
  vector<int> lt(n, INT_MAX);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    par[i] = i;
  }
  vector<int> s = {};
  for (int i = 0; i < n; ++i) {
    while (!s.empty() && v[s.back()] < v[i]) {
      s.pop_back();
    }
    if (s.empty()) {
      s.push_back(i);
      continue;
    }
    if (v[i] < v[s.back()]) {
      while (!(lt[s.back()] == INT_MAX || ch[s.back()] < lt[s.back()])) {
        s.pop_back();
      }
      lt[i] = ++ch[s.back()];
      s.push_back(i);
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (lt[i] == INT_MAX) continue;
    cnt = max(cnt, lt[i]);
  }
  cout << cnt << "\n";
}
