#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 100;
int dp[N];
int b[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  int Max = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    while (!v.empty()) {
      int ind = v.back();
      if (b[ind] < b[i]) {
        dp[i] = max(dp[i], dp[ind] + 1);
        v.pop_back();
      } else {
        dp[i] = max(dp[i], 1);
        break;
      }
    }
    if (v.empty()) dp[i] = 0;
    Max = max(Max, dp[i]);
    v.push_back(i);
  }
  cout << Max;
  cin >> n;
}
