#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int a[100001], n, num, siz = 0, sq;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> kill(n, 1);
  stack<int> s;
  s.push(0);
  kill[0] = 1000000000;
  for (int i = 1; i < n; i++) {
    while (!s.empty() && a[i] > a[s.top()]) {
      kill[i] = max(kill[s.top()] + 1, kill[i]);
      s.pop();
    }
    s.push(i);
  }
  num = 0;
  for (int i = 0; i < n; i++)
    if (kill[i] < 1000000000) num = max(num, kill[i]);
  cout << num;
}
