#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], i, fl = 0;
  for (i = 0; i < n; i++) cin >> a[i];
  stack<int> s;
  for (i = 1; i < n; i++)
    if (a[i] < a[i - 1]) fl = 1;
  if (fl == 0) {
    cout << "0\n";
    return 0;
  }
  int store[n + 1][2], last;
  memset(store, 0, sizeof(store));
  store[a[0]][0] = 1;
  store[a[0]][1] = 1000000007;
  last = a[0];
  s.push(a[0]);
  for (i = 1; i < n; i++) {
    if (a[i] < last)
      last = a[i];
    else {
      while (!s.empty()) {
        if (s.top() > a[i]) {
          if (store[s.top()][1] < store[s.top()][0] + 1) {
            s.pop();
            continue;
          }
          store[s.top()][0]++;
          store[a[i]][1] = store[s.top()][0];
          s.push(a[i]);
          store[a[i]][0]++;
          break;
        } else {
          s.pop();
        }
      }
      if (s.empty()) {
        s.push(a[i]);
        store[a[i]][0] = 1;
        store[a[i]][1] = 1000000007;
      }
      last = a[i];
    }
  }
  int maxx = 0;
  for (i = 1; i <= n; i++) maxx = max(maxx, store[i][0]);
  cout << maxx << endl;
  return 0;
}
