#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
vector<int> v;
int main() {
  int n;
  while (cin >> n) {
    v.clear();
    memset(a, 0, sizeof(a));
    int x;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      int cnt = 0;
      if (v.empty()) {
        v.push_back(x);
      } else {
        while (v.back() < x) {
          cnt = max(cnt, a[v.back()]);
          v.pop_back();
          if (v.empty()) break;
        }
        if (v.empty())
          v.push_back(x);
        else {
          a[x] = cnt + 1;
          v.push_back(x);
        }
      }
    }
    int res = 0;
    for (int i = 0; i <= n; i++) res = max(res, a[i]);
    cout << res << endl;
  }
  return 0;
}
