#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int mod = 7 + 1e9;
const int N = (1 << 19);
const long long OO = (long long)1 * 1e9;
int main() {
  cin.sync_with_stdio(0);
  int n, mx = 0, a;
  stack<pair<int, int>> x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (!x.empty())
      if (x.top().first > a) {
        mx = max(mx, x.top().second);
        break;
      } else {
        x.pop();
        if (x.size()) {
          while (x.size() > 1) {
            pair<int, int> t = x.top();
            x.pop();
            if (x.top().second > t.second) {
              x.push(t);
              break;
            }
          }
          x.top().second++;
        }
      }
    x.push(make_pair(a, 1));
  }
  cout << mx;
  return 0;
}
