#include <bits/stdc++.h>
using namespace std;
struct st {
  int x;
  int r;
};
int main() {
  int n, i, j, k;
  cin >> n;
  int arr[n + 1];
  for (int i = 0; i < n; i += 1) {
    cin >> arr[i + 1];
  }
  int res = 0;
  int mx = arr[1];
  stack<st> s1;
  s1.push({arr[1], INT_MAX});
  for (i = 2; i <= n; i++) {
    st t = s1.top();
    if (t.x > arr[i]) {
      st t1 = {arr[i], 1};
      res = max(1, res);
      s1.push(t1);
      continue;
    }
    int cnt = 1;
    while (t.x < arr[i] && !s1.empty()) {
      s1.pop();
      cnt = max(cnt, t.r + 1);
      if (!s1.empty()) t = s1.top();
    }
    if (s1.empty()) {
      s1.push({arr[i], INT_MAX});
    } else {
      s1.push({arr[i], cnt});
      res = max(res, cnt);
    }
  }
  cout << res << "\n";
}
