#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
queue<int> q1, q2;
class psy {
 public:
  int l, r, val, del;
} c[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  c[0].val = 0;
  c[n + 1].val = inf;
  for (int i = 1; i <= n; i++) {
    cin >> c[i].val;
    c[i].l = i - 1, c[i].r = i + 1;
  }
  for (int i = 2; i <= n; i++) {
    if (c[i - 1].val > c[i].val) q1.push(i);
  }
  int ans = 0;
  while (!q1.empty()) {
    ans++;
    while (!q1.empty()) {
      int x = q1.front();
      q1.pop();
      c[x].del = 1;
      c[c[x].l].r = c[x].r;
      c[c[x].r].l = c[x].l;
      q2.push(c[x].r);
    }
    while (!q2.empty()) {
      int x = q2.front();
      q2.pop();
      if (c[c[x].l].val > c[x].val && !c[x].del) q1.push(x);
    }
  }
  cout << ans << "\n";
  return 0;
}
