#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
vector<pair<int, int> > a;
int b[N];
int main() {
  int n, x, ans = 0;
  scanf("%d", &n);
  for (int i = n - 1; i >= 0; i--) scanf("%d", &b[i]);
  for (int i = 0; i < n; i++) {
    x = b[i];
    int t = 0, pnt = a.size() - 1;
    while (pnt >= 0 && a[pnt].first < x) {
      t++;
      t = max(t, a[pnt].second);
      a.pop_back();
      pnt--;
    }
    a.push_back(make_pair(x, t));
    ans = max(ans, t);
  }
  cout << ans;
}
