#include <bits/stdc++.h>
const int N = 500500;
const int Q = 1 << 21;
const long long mod = 998244353;
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  stack<pair<int, int> > S;
  int ans = 0;
  S.push(make_pair(V[0], N));
  for (int i = 1; i < N; i++) {
    int a = 0;
    while (!S.empty()) {
      if (S.top().first < V[i]) {
        a = S.top().second + 1;
        S.pop();
        continue;
      }
      ans = max(ans, a + 1);
      while (!S.empty()) {
        if (S.top().second != a) break;
        S.pop();
      }
      S.push(make_pair(V[i], a));
      break;
    }
    if (S.empty()) S.push(make_pair(V[i], N));
  }
  cout << ans << "\n";
}
