#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
set<int> blocks[MAX];
int ind = 0;
inline int getE(set<int> &s) { return *s.rbegin(); }
inline int getB(set<int> &s) { return *s.begin(); }
int main() {
  int N, v;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> v;
    if (blocks[ind].size() && v < getE(blocks[ind])) ind++;
    blocks[ind].insert(v);
  }
  ++ind;
  vector<int> active;
  for (int i = 0; i < ind; ++i) active.push_back(i);
  for (int i = 1; i <= N; ++i) {
    bool change = false;
    vector<int> back;
    for (int j = active.size() - 2; j >= 0; --j) {
      int x = active[j];
      int y = active[j + 1];
      if (getE(blocks[x]) > getB(blocks[y])) {
        blocks[y].erase(blocks[y].begin());
        change = true;
      }
      if (blocks[y].size()) back.push_back(y);
    }
    back.push_back(active[0]);
    reverse(back.begin(), back.end());
    active = back;
    if (!change) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  return 0;
}
