#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int y[100001];
int main() {
  int a, b, c, d, e, f, i, j, p = 0, q = 0;
  int x[100001], y[100001];
  cin >> a;
  for (i = 0; i < a; i++) {
    cin >> x[i];
  }
  y[0] = 1000001;
  s.push(0);
  for (i = 1; i < a; i++) {
    y[i] = 1;
    while (!s.empty() && x[i] > x[s.top()]) {
      y[i] = max(y[i], y[s.top()] + 1);
      s.pop();
    }
    s.push(i);
  }
  for (i = 0; i < a; i++) {
    if (y[i] < 1000001) p = max(p, y[i]);
  }
  cout << p << endl;
  return 0;
}
