#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long int> a(n + 1);
    for (long long int i = 1; i < n + 1; i++) cin >> a[i];
    stack<long long> s;
    s.push(0);
    vector<long long int> b(n + 1, 1000000007);
    for (long long int i = 1; i < n + 1; i++) {
      b[i] = 1;
      while ((long long int)s.size() && a[i] > a[s.top()]) {
        b[i] = max(b[i], b[s.top()] + 1);
        s.pop();
      }
      s.push(i);
    }
    for (long long int i = 0; i < n + 1; i++)
      if (b[i] >= 1000000007) b[i] = 0;
    cout << *max_element((b).begin(), (b).end());
  }
  return 0;
}
