#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = int(1e5);
int a[N + 10], _prev[N + 10], _next[N + 10];
vector<int> del, ndel;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (i - 1 >= 0) {
      _prev[i] = i - 1;
    } else {
      _prev[i] = -1;
    }
    if (i + 1 < n) {
      _next[i] = i + 1;
    } else {
      _next[i] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (_next[i] != -1 && a[i] > a[_next[i]]) {
      del.push_back(_next[i]);
    }
  }
  int ans = 0;
  while (int((del).size()) > 0) {
    ans++;
    int i = 0;
    ndel.clear();
    while (i < int((del).size())) {
      int j = i;
      while (j + 1 < int((del).size()) && _next[del[j]] == del[j + 1]) {
        j++;
      }
      if (_prev[del[i]] != -1) {
        _next[_prev[del[i]]] = _next[del[j]];
      }
      if (_next[del[j]] != -1) {
        _prev[_next[del[j]]] = _prev[del[i]];
      }
      if (_prev[del[i]] != -1 && _next[del[j]] != -1) {
        if (a[_prev[del[i]]] > a[_next[del[j]]]) {
          ndel.push_back(_next[del[j]]);
        }
      }
      i = j + 1;
    }
    del = ndel;
  }
  printf("%d\n", ans);
  return 0;
}
