#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
const int inf = 0x3f3f3f3f;
long long mod = 998244353;
const double eps = 1e-9;
const double pi = acos(-1);
const double e = 2.718281828;
int n, m, w, k;
int ans[maxn];
int sta[maxn];
int a[maxn];
int main() {
  int _;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int as = 0;
  int l = 0;
  for (int i = n - 1; i >= 0; i--) {
    sta[l++] = a[i];
    while (l > 1 && sta[l - 1] > sta[l - 2]) {
      if (ans[sta[l - 2]] > ans[sta[l - 1]])
        ans[sta[l - 1]] = ans[sta[l - 2]];
      else
        ans[sta[l - 1]]++;
      sta[l - 2] = sta[l - 1];
      l--;
    }
    as = max(as, ans[sta[l - 1]]);
  }
  cout << as << endl;
}
