#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct event {
  int t, x;
  event(int a = 0, int b = 0) {
    t = a;
    x = b;
  }
  bool operator<(const event &a) const {
    if (t != a.t) return t < a.t;
    return x > a.x;
  }
};
int n, t;
int a[MAXN], r[MAXN];
set<event> s;
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r[i] = i + 1;
  }
  a[n] = n + 1;
  for (int i = 0; i < n - 1; i++)
    if (a[i] > a[i + 1]) s.insert(event(0, i));
  t = -1;
  while (!s.empty()) {
    event curr = *s.begin();
    s.erase(curr);
    if (curr.t > t) t++;
    int x = curr.x;
    r[x] = r[r[x]];
    if (a[x] > a[r[x]]) s.insert(event(t + 1, x));
  }
  cout << t + 1 << endl;
  return 0;
}
