#include <bits/stdc++.h>
using namespace std;
template <class T>
void mini(T& a, T b) {
  a = min(a, b);
}
template <class T>
void maxi(T& a, T b) {
  a = max(a, b);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  return out << a.first << " " << a.second;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <class T>
void out(T a) {
  cout << a << endl;
}
void out() { cout << "OK" << endl; }
const int N = 1e5 + 5;
int a[N];
vector<int> b;
vector<int> c;
int to[N];
void Solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    to[i] = i + 1;
    if (a[i] > a[i + 1]) {
      b.push_back(i);
    }
  }
  int ans = 0;
  a[0] = n + 1;
  while (!b.empty()) {
    int last = 0;
    c.clear();
    c.push_back(b[0]);
    for (int i = 1; i < b.size(); i++) {
      if (b[i] == to[c.back()]) {
        to[c.back()] = to[b[i]];
      } else {
        c.push_back(b[i]);
      }
    }
    b.clear();
    for (int i : c) {
      to[i] = to[to[i]];
      if (a[i] > a[to[i]]) {
        b.push_back(i);
      }
    }
    ans++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Solve();
  return 0;
}
