#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
long long n, a[N], tp, us[N], kol[N], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int t = 0;
    while (tp > 0 && a[us[tp - 1]] < a[i]) {
      kol[i] = t = max(t + 1ll, kol[us[--tp]]);
    }
    us[tp++] = i;
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, kol[i]);
  }
  cout << ans;
  return 0;
}
