#include <bits/stdc++.h>
using namespace std;
int a[100010], _right[100010], dp[100010], segtree[4 * 100010 + 10];
stack<int> s;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  _right[n] = n + 1;
  s.push(n);
  for (int i = n - 1; i >= 0; i--) {
    while (!s.empty()) {
      if (a[s.top()] > a[i]) {
        _right[i] = s.top();
        break;
      }
      s.pop();
    }
    if (s.empty()) _right[i] = n + 1;
    s.push(i);
  }
  dp[n] = 0;
  int cur, pos, ans, q;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] < a[i + 1]) {
      dp[i] = 0;
      continue;
    }
    if (_right[i] == _right[i + 1]) {
      dp[i] = max(dp[i + 1], 1);
      continue;
    }
    ans = 0;
    cur = 0;
    pos = i + 1;
    while (1) {
      if (pos == _right[i]) break;
      q = dp[pos];
      ans++;
      ans = max(ans, q);
      pos = _right[pos];
    }
    dp[i] = ans;
  }
  int answer = 0;
  for (int i = 1; i <= n; i++) answer = max(answer, dp[i]);
  cout << answer << endl;
  return 0;
}
