#include <bits/stdc++.h>
using namespace std;
int n, x, ans, d[100001];
vector<int> a, cur;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n && cin >> x; i++) a.push_back(x);
  d[0] = -1;
  cur.push_back(0);
  for (int i = 1; i < n; i++) {
    while (cur.size() && a[cur.back()] < a[i]) {
      d[i] = max(d[i], d[cur.back()] + 1);
      cur.pop_back();
    }
    if (cur.size() == 0) d[i] = -1;
    cur.push_back(i);
    ans = max(ans, d[i] + 1);
  }
  cout << ans << endl;
  return 0;
}
