#include <bits/stdc++.h>
using namespace std;
long long int test, n;
long long int sum, ans;
void the_happiest_place_on_earth() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int N = 200040;
long long int a[N], b[N], c[N], par[N], Size[N], present[N], color[N];
void testcase() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> step(n, 0), kills(n, 0);
  deque<pair<int, int>> second;
  int an = 0;
  for (int i = n - 1; i >= 0; i--) {
    int cur = 0;
    while (!second.empty() && (a[i] > second.front().first)) {
      cur = max(cur + 1, second.front().second);
      second.pop_front();
    }
    an = max(an, cur);
    second.push_front({a[i], cur});
  }
  cout << an << "\n";
  return;
}
int main() {
  the_happiest_place_on_earth();
  test = 1;
  int t = 0;
  while (test--) {
    testcase();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
