#include <bits/stdc++.h>
using namespace std;
pair<int, int> cnt[400001];
int main() {
  int n, cur;
  cin >> n;
  int c = 0;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> cur;
    int life = 0;
    while (c && cnt[c - 1].first < cur) {
      life += cnt[c - 1].second;
      --c;
    }
    if (c) {
      cnt[c - 1].second--;
      if (cnt[c - 1].second == 0) --c;
      res = max(res, life + 1);
      cnt[c++] = make_pair(cur, life + 1);
    } else
      cnt[c++] = make_pair(cur, 1000000001);
  }
  cout << res << '\n';
}
