#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, M = 3e5 + 7;
int powe(int x, int y) {
  x = x % mod;
  int ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int arr[n], par[n], ran[n], kills[n];
  memset(kills, 0, sizeof(kills));
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  par[0] = 0;
  ran[0] = -1;
  for (int i = 1; i < n; i++) {
    int j = i - 1;
    while (arr[j] < arr[i]) {
      if (j == par[j]) {
        break;
      }
      j = par[j];
    }
    if (arr[j] < arr[i]) {
      ran[i] = -1;
      par[i] = i;
    } else {
      while (ran[j] == kills[j] && ran[j] != -1) {
        j = par[j];
      }
      par[i] = j;
      kills[j]++;
      ran[i] = kills[j];
    }
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, kills[i]);
  }
  cout << mx;
  return 0;
}
