#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 5;
int a[M];
int res[M];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  stack<int> st;
  for (int i = 1; i <= n; i++) {
    if (st.empty()) {
      st.push(i);
      res[i] = 0;
    } else {
      if (a[st.top()] > a[i]) {
        res[i] = 1;
        st.push(i);
      } else {
        while (!st.empty() && a[st.top()] < a[i]) {
          int val = st.top();
          st.pop();
          res[i] = max(res[i], res[val] + 1);
        }
        if (st.empty()) {
          res[i] = 0;
          st.push(i);
        } else {
          st.push(i);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, res[i]);
  }
  cout << ans << endl;
  return 0;
}
