#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int N = 100100;
int S[N], T[N], a[N], n, ans, top;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    while (S[top] < a[i] && top > 0) top--;
    if (top > 0) {
      T[top]++;
      ans = max(ans, T[top]);
    }
    while (top >= 2 && T[top] == T[top - 1]) top--;
    S[++top] = a[i];
    T[top] = 0;
  }
  cout << ans;
}
