#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
int a[MAX], dp[MAX];
vector<pair<long long, long long> > v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  v.push_back({INF, n});
  for (int i = n - 1; i >= 0; i--) {
    while (a[i] > v.back().first) {
      dp[i] += max(dp[v.back().second] - dp[i], 1);
      v.pop_back();
    }
    ans = max(ans, dp[i]);
    v.push_back({a[i], i});
  }
  cout << ans;
  return 0;
}
