#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
int niz[maxn];
int kad[maxn];
stack<int> stek;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> niz[i];
  kad[1] = -1;
  int rez = 0;
  for (int i = 1; i <= n; i++) {
    int x = niz[i];
    while (!stek.empty()) {
      int koji = stek.top();
      if (niz[koji] > x) {
        rez = max(rez, kad[i] + 1);
        break;
      }
      stek.pop();
      kad[i] = max(kad[i], kad[koji] + 1);
    }
    stek.push(i);
  }
  cout << rez << endl;
  return 0;
}
