#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, t, a;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int steps[n + 1];
  steps[0] = -1;
  stack<int> s;
  steps[arr[0]] = -1;
  s.push(arr[0]);
  int mx;
  for (i = 1; i < n; i++) {
    if (arr[i] < arr[i - 1]) {
      steps[arr[i]] = 1;
      s.push(arr[i]);
    } else {
      mx = 0;
      while (s.empty() == 0 && arr[i] > s.top()) {
        mx = max(mx, steps[s.top()]);
        s.pop();
      }
      if (s.empty()) {
        steps[arr[i]] = -1;
      } else {
        steps[arr[i]] = 1 + mx;
      }
      s.push(arr[i]);
    }
  }
  mx = 0;
  for (auto z : steps) {
    mx = max(mx, z);
  }
  cout << mx;
  return 0;
}
