#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long bin(long long a, long long b) {
  if (b == 0) return 1;
  if (b & 1) return (a * bin((a * a) % mod, b / 2)) % mod;
  return (1 * bin((a * a) % mod, b / 2)) % mod;
}
void I_m_Beast() {
  int n, a;
  cin >> n;
  int A[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> A[i];
  }
  vector<pair<int, int> > v;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int cur = 0;
    while (v.size() and v.back().first < A[i]) {
      cur = max(cur, v.back().second);
      v.pop_back();
    }
    if (v.empty())
      cur = 0;
    else
      cur++;
    v.push_back({A[i], cur});
    ans = max(ans, cur);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    I_m_Beast();
  }
  return 0;
}
