#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long mod) {
  long long c = 1;
  while (b > 0) {
    if (b % 2) c *= a, c %= mod;
    b /= 2;
    a *= a;
    a %= mod;
  }
  return c;
}
long long val[100005];
int main() {
  long long n;
  cin >> n;
  long long arr[n + 1];
  for (long long i = 0; i < n; i++) cin >> arr[i + 1];
  long long m = arr[0];
  stack<long long> st;
  st.push(0);
  long long a = 0;
  val[0] = 1000000007;
  arr[0] = 0;
  for (long long i = 1; i <= n; i++) {
    val[i] = 1;
    while ((!st.empty()) && (arr[i] > arr[st.top()])) {
      val[i] = max(val[i], val[st.top()] + 1);
      st.pop();
    }
    st.push(i);
    if (val[i] < 1000000007) a = max(a, val[i]);
  }
  cout << a;
}
