#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[N], n, ans = -1, f[N];
stack<int> st;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) {
    f[i] = -1;
    while (!st.empty() && a[st.top()] <= a[i]) {
      int x = st.top();
      f[i] = max(f[i], f[x]);
      st.pop();
    }
    if (st.empty())
      f[i] = -1;
    else
      ++f[i];
    ans = max(ans, f[i]);
    st.push(i);
  }
  printf("%d", ans + 1);
  return 0;
}
