#include <bits/stdc++.h>
using namespace std;
static const int maxn = 2e5 + 5;
struct Node {
  bool ok;
  int val;
  int pos, rpos;
  Node(bool ok = 0, int val = 0, int pos = 0, int rpos = 0)
      : ok(ok), val(val), pos(pos), rpos(rpos) {}
  bool operator<(const Node &other) const {
    if (ok and other.ok) {
      if (val == other.val) return pos > other.pos;
      return val < other.val;
    }
    return ok > other.ok;
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> arr(n + 2);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  vector<int> rgt(n + 1);
  rgt[n] = -1;
  for (int i = n - 1; i >= 1; i--) rgt[i] = i + 1;
  multiset<Node> ms;
  arr[n + 1] = 1e9 + 9;
  for (int i = 1; i <= n; i++) {
    bool ok = arr[i] > arr[i + 1];
    ms.insert(Node(ok, arr[i], i, i + 1));
  }
  int min_time = 0;
  map<int, int> mp;
  while (ms.size()) {
    int cnt = 0;
    mp.clear();
    while (ms.size()) {
      auto it = *ms.begin();
      if (it.ok == false) break;
      ++cnt;
      ms.erase(it);
      rgt[it.pos] = rgt[it.rpos];
      mp[rgt[it.rpos]] = it.pos;
    }
    if (cnt == 0) break;
    ++min_time;
    for (auto it : mp) {
      if (it.first == -1) continue;
      int pos = it.second;
      int rpos = it.first;
      bool ok = arr[pos] > arr[rpos];
      ms.insert(Node(ok, arr[pos], pos, rpos));
    }
  }
  cout << min_time << '\n';
}
