#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N], sg[4 * N];
void build(int node, int l, int r) {
  if (l == r) {
    sg[node] = a[l];
    return;
  }
  int mid = (l + r) / 2;
  build(2 * node, l, mid);
  build(2 * node + 1, mid + 1, r);
  sg[node] = max(sg[2 * node], sg[2 * node + 1]);
}
int que(int node, int l, int r, int ll, int rr) {
  if (l > rr || r < ll) return 0;
  if (l >= ll && r <= rr) return sg[node];
  int mid = (l + r) / 2;
  int q1 = que(2 * node, l, mid, ll, rr);
  int q2 = que(2 * node + 1, mid + 1, r, ll, rr);
  return max(q1, q2);
}
void update(int node, int l, int r, int pt, int val) {
  if (pt > r || pt < l) return;
  if (l == r) {
    sg[node] = val;
    return;
  }
  int mid = (l + r) / 2;
  update(2 * node, l, mid, pt, val);
  update(2 * node + 1, mid + 1, r, pt, val);
  sg[node] = max(sg[2 * node], sg[2 * node + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  deque<pair<int, int>> dq;
  for (int i = 0; i < n; i++) {
    int val = 0;
    while (dq.size() && dq.back().first < a[i]) {
      dq.pop_back();
    }
    if (dq.size()) {
      int mx = que(1, 0, n - 1, dq.back().second + 1, i);
      val = mx + 1;
    }
    dq.push_back(make_pair(a[i], i));
    update(1, 0, n - 1, i, val);
  }
  cout << que(1, 0, n - 1, 0, n - 1);
  return 0;
}
