#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int p[n + 1];
  p[1] = 0;
  stack<int> myStack;
  myStack.push(1);
  for (int i = 2; i <= n; i++) {
    if (a[i - 1] > a[i]) {
      p[i] = 1;
      myStack.push(i);
    } else {
      p[i] = 0;
      while (!myStack.empty()) {
        if (a[myStack.top()] < a[i]) {
          p[i] = max(p[i], p[myStack.top()] + 1);
          myStack.pop();
        } else {
          break;
        }
      }
      if (int(myStack.size()) == 0) {
        p[i] = 0;
      }
      myStack.push(i);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, p[i]);
  }
  cout << ans << endl;
}
