#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, a[N];
pair<int, int> tree[4 * N];
set<int> eaters;
void build(int i, int l, int r) {
  if (l == r) {
    tree[i] = make_pair(1, l);
    return;
  }
  int mid = (l + r) / 2;
  build(2 * i, l, mid);
  build(2 * i + 1, mid + 1, r);
  tree[i].first = tree[2 * i].first + tree[2 * i + 1].first;
  tree[i].second = tree[2 * i].second;
}
int query(int i, int start, int end, int l, int r) {
  if (l <= start && r >= end) return tree[i].first ? tree[i].second : -1;
  if (r < start || l > end) return -1;
  int mid = (start + end) / 2;
  int lft = query(2 * i, start, mid, l, r);
  if (lft != -1) return lft;
  return query(2 * i + 1, mid + 1, end, l, r);
}
void update(int i, int start, int end, int upd) {
  if (start == end) {
    tree[i] = make_pair(0, -1);
    return;
  }
  int mid = (start + end) / 2;
  if (upd <= mid)
    update(2 * i, start, mid, upd);
  else
    update(2 * i + 1, mid + 1, end, upd);
  tree[i].first = tree[2 * i].first + tree[2 * i + 1].first;
  if (tree[2 * i].second != -1)
    tree[i].second = tree[2 * i].second;
  else
    tree[i].second = tree[2 * i + 1].second;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n); ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  for (int i = (1); i <= (int)(n); ++i) {
    int j = i;
    while (j + 1 <= n and a[j + 1] >= a[j]) ++j;
    if (j < n) eaters.insert(j);
    i = j;
  }
  int ans = 0;
  while (true) {
    vector<int> eaten;
    for (int i : eaters) {
      int nxt = query(1, 1, n, i + 1, n);
      if (nxt != -1 and a[nxt] < a[i]) eaten.push_back(nxt);
    }
    for (int i : eaten) {
      update(1, 1, n, i);
      if (eaters.find(i) != eaters.end()) eaters.erase(i);
    }
    if (!((int)(eaten).size())) break;
    ++ans;
  }
  cout << ans;
}
