#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int n, a[100010], ans[100010], res;
stack<int> second;
int main() {
  cin >> n;
  for (int i = n - 1; i >= 0; i--) cin >> a[i];
  for (int i = 0; i < n; i++) {
    while (!second.empty() && a[i] > a[second.top()]) {
      int p = second.top();
      ans[i] = max(ans[i] + 1, ans[p]);
      second.pop();
    }
    second.push(i);
    res = max(res, ans[i]);
  }
  cout << res << endl;
  return 0;
}
