#include <bits/stdc++.h>
using namespace std;
long long pows[105];
const int mod = 1000 * 1000 * 1000 + 7;
int ans;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  stack<pair<int, int>> alive;
  for (int i = n - 1; i >= 0; i--) {
    int c = 0;
    while (!alive.empty() && alive.top().first < v[i]) {
      c = max(c + 1, alive.top().second);
      alive.pop();
    }
    ans = max(ans, c);
    pair<int, int> p;
    p.first = v[i];
    p.second = c;
    alive.push(p);
  }
  cout << ans << endl;
}
