#include <bits/stdc++.h>
using namespace std;
int arr[100100], n, top = 0, sta[100100], ans = 0, f[100100];
struct node {
  int i;
  int v;
};
node book[100100];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = n; i >= 1; i--) {
    int t = 0;
    while (top && book[top].v < arr[i]) {
      f[i] = t = max(++t, f[book[top].i]);
      top--;
    }
    book[++top].i = i, book[top].v = arr[i];
    ans = max(ans, f[i]);
  }
  cout << ans << endl;
  return 0;
}
