#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  std::cin >> n;
  list<int> li;
  li.push_back(0);
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    li.push_back(a);
  }
  li.push_back(1000000);
  vector<list<int>::iterator> q;
  int last = 0;
  for (list<int>::iterator it = ++li.begin(), prev_it = li.begin();
       it != li.end(); ++it, ++prev_it) {
    if (last<*prev_it&& * prev_it> * it) {
      q.push_back(prev_it);
    }
    last = *prev_it;
  }
  int steps = 0;
  while (!q.empty()) {
    ++steps;
    vector<list<int>::iterator> tmp;
    for (int i = 0; i < q.size(); ++i) {
      list<int>::iterator first = q[i], last = q[i];
      int value = *first;
      for (++last; *last < value; ++last) {
        value = *last;
      }
      li.erase(++first, last);
      first = q[i], last = q[i];
      if (*q[i] > *(--first) && *q[i] > *(++last)) {
        tmp.push_back(q[i]);
      }
    }
    q.swap(tmp);
  }
  std::cout << steps << std::endl;
  return 0;
}
