#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int a[100010], r[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> q;
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    r[i] = i + 1;
    if (i) {
      if (a[i - 1] > a[i]) {
        q.push_back(i - 1);
      }
    }
  }
  r[n - 1] = -1;
  long long int steps = 0;
  while (q.empty() == 0) {
    steps++;
    sort(q.rbegin(), q.rend());
    vector<long long int> nq;
    for (auto i : q) {
      r[i] = r[r[i]];
      if (r[i] != -1 && a[r[i]] < a[i]) nq.push_back(i);
    }
    q = nq;
  }
  cout << steps << endl;
}
