#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 4e18;
const long long MAX = 1e5;
const long double PI = 3.14159265358979323846;
long long MA = -INF, MI = INF;
long long PO(long long x, long long y) {
  if (y == 0) return 1;
  long long ans = PO(x, y / 2);
  ans *= ans, ans %= MOD;
  if (y % 2 == 1) ans *= x, ans %= MOD;
  return ans % MOD;
}
void RE(long long x) {
  x %= MOD;
  if (x < 0) x += MOD;
}
stack<long long> ps;
long long death[MAX + 10], id[MAX + 10];
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(10);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> id[i];
    while (!ps.empty() && id[ps.top()] < id[i])
      death[i] = max(death[i], death[ps.top()] + 1), ps.pop();
    if (ps.empty()) death[i] = -1;
    MA = max(MA, death[i] + 1);
    ps.push(i);
  }
  cout << MA;
  return 0;
}
