#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n;
int t[2 * N];
void build() {
  for (int i = n - 1; i > 0; --i) t[i] = max(t[i << 1], t[i << 1 | 1]);
}
void modify(int p, int value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
}
int query(int l, int r) {
  int res = t[n + l];
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(res, t[--r]);
  }
  return res;
}
int main() {
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i <= n - 1; i++) cin >> v[i];
  for (long long int i = 0; i <= n - 1; i++) t[n + i] = 0;
  build();
  vector<long long int> l(n, -1);
  stack<long long int> s;
  for (long long int i = 0; i <= n - 1; i++) {
    while (!s.empty() && v[s.top()] < v[i]) s.pop();
    if (s.empty()) {
      s.push(i);
      continue;
    }
    l[i] = s.top();
    s.push(i);
  }
  long long int ans = 0;
  for (long long int i = 0; i <= n - 1; i++) {
    long long int le = l[i], ri = i;
    if (le == -1) continue;
    if (le + 1 == ri) {
      ans = max(ans, 1LL);
      modify(i, 1);
      continue;
    }
    long long int ma = query(le + 1, ri);
    ans = max(ans, ma + 1);
    modify(i, ma + 1);
  }
  cout << ans << "\n";
}
