#include <bits/stdc++.h>
using namespace std;
long long int tree[500001], n, arr[100001], prev1[100001];
void build(long long int node, long long int a, long long int b) {
  if (a == b) {
    tree[node] = 0;
    return;
  }
  long long int mid = (a + b) / 2;
  build(2 * node, a, mid);
  build(2 * node + 1, mid + 1, b);
}
void update(long long int node, long long int a, long long int b,
            long long int ind, long long int val) {
  if (a > b || ind < a || ind > b) return;
  if (a == b && a == ind) {
    tree[node] = val;
    return;
  }
  long long int mid = (a + b) / 2;
  update(2 * node, a, mid, ind, val);
  update(2 * node + 1, mid + 1, b, ind, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
long long int query(long long int node, long long int a, long long int b,
                    long long int l, long long int r) {
  if (a > b || r < a || b < l) return -10000000000;
  if (a >= l && b <= r) return tree[node];
  long long int mid = (a + b) / 2;
  return max(query(2 * node, a, mid, l, r),
             query(2 * node + 1, mid + 1, b, l, r));
}
int main() {
  long long int i, j, ans = 0, q;
  cin >> n;
  for (i = 0; i < n; i++) {
    prev1[i] = -1;
    cin >> arr[i];
  }
  build(1, 1, n);
  prev1[0] = -1;
  for (i = 1; i < n; i++) {
    j = i - 1;
    while (1) {
      if (j == -1 || arr[j] > arr[i]) break;
      j = prev1[j];
    }
    prev1[i] = j;
  }
  for (i = 1; i < n; i++) {
    if (prev1[i] == -1) continue;
    q = query(1, 0, n - 1, prev1[i] + 1, i);
    q++;
    update(1, 0, n - 1, i, q);
    ans = max(ans, q);
  }
  cout << ans;
}
