#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n;
int a[maxn], b[maxn], d[maxn], r = -1;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int mx = 0;
    while (r >= 0 && a[i] > a[b[r]]) mx = max(mx, d[b[r--]]);
    if (r >= 0) d[i] = mx + 1;
    b[++r] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, d[i]);
  }
  cout << ans << endl;
  return 0;
}
