#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
int n;
int a[maxn];
stack<pair<int, int> > st;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (st.empty()) {
      st.push(make_pair(a[i], 0));
    } else {
      int m = 0;
      while (st.size() && st.top().first <= a[i]) {
        m = max(m, st.top().second);
        st.pop();
      }
      if (st.empty()) m = -1;
      st.push(make_pair(a[i], m + 1));
      ans = max(ans, m + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
inline void getInt(int* p) {
  char ch;
  do {
    ch = getchar();
  } while (ch == ' ' || ch == '\n');
  if (ch == '-') {
    *p = -(getchar() - '0');
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 - ch + '0';
    }
  } else {
    *p = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 + ch - '0';
    }
  }
}
