#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
  ios::sync_with_stdio(0);
  run();
}
long long val[100000];
struct evt {
  int a, b;
  bool operator<(evt const &u) const { return a != u.a ? a < u.a : b < u.b; }
};
void run() {
  long long n;
  cin >> n;
  set<int> alive;
  vector<evt> todo;
  for (int i = 0; i < n; i++) {
    cin >> val[i];
    alive.insert(i);
    if (i and val[i] < val[i - 1]) todo.push_back({i - 1, i});
  }
  int steps = 0;
  for (;; ++steps) {
    if (alive.empty() or todo.empty()) break;
    vector<pair<int, int>> will;
    for (auto i : todo) {
      if (alive.count(i.a) and alive.count(i.b)) will.emplace_back(i.a, i.b);
    }
    for (auto i : will) {
      alive.erase(i.second);
    }
    todo.clear();
    for (auto i : will) {
      if (alive.count(i.first)) {
        auto a = alive.find(i.first);
        auto b = a;
        ++b;
        if (b != alive.end() and val[*b] < val[*a]) {
          todo.push_back({*a, *b});
        }
      }
    }
  }
  cout << steps << endl;
}
