#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
  if (b == 0) {
    return 1 % mod;
  }
  long long x = powmod(a, b / 2, mod);
  x = (x * x) % mod;
  if (b & 1) {
    x = (a * x) % mod;
  }
  return x;
}
const int INF = 1000000000;
const long double EPS = 1e-9;
const long double PI = (long double)(3.1415926535897932384626433832795);
int debug = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int fans = 0;
  stack<pair<int, int> > S;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; ++i) {
    if (S.empty()) {
      S.push(make_pair(arr[i], 0));
    } else {
      if (arr[i] < S.top().first) {
        S.push(make_pair(arr[i], 1));
        fans = max(fans, 1);
      } else {
        int temp_max = 0;
        while (!S.empty() && arr[i] > S.top().first) {
          temp_max = max(S.top().second, temp_max);
          S.pop();
        }
        if (S.empty()) {
          S.push(make_pair(arr[i], 0));
        } else {
          S.push(make_pair(arr[i], temp_max + 1));
          fans = max(temp_max + 1, fans);
        }
      }
    }
  }
  cout << fans << "\n";
  return 0;
}
