#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000001;
int dx[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
int main() {
  cin.tie(0);
  cout.tie(0);
  std::ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long arr[n], f[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  stack<long long> s;
  for (int i = 0; i < n; i++) {
    f[i] = 1;
    while (!s.empty() && arr[i] > arr[s.top()]) {
      f[i] = max(f[i], f[s.top()] + 1);
      s.pop();
    }
    if (s.empty()) f[i] = n + 1;
    s.push(i);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] <= n) ans = max(ans, f[i]);
  }
  cout << ans;
  return 0;
}
