#include <bits/stdc++.h>
struct person {
  int id;
  int die = 0;
  person *by = 0;
};
std::vector<person> list(0);
int main() {
  int n;
  std::cin >> n;
  list.resize(n);
  int maxDie = 0, maxID = 0;
  std::cin >> list[0].id;
  for (int i = 1; i < n; ++i) {
    std::cin >> list[i].id;
    int cnt = 0;
    if (list[i - 1].id > list[i].id) {
      list[i].by = &list[i - 1];
      list[i].die = 1;
      cnt = 1;
    } else {
      cnt = list[i - 1].die > 1 ? list[i - 1].die : 1;
      bool found = false;
      for (person *cur = list[i - 1].by; cur != 0; cur = cur->by) {
        if (cur->id > list[i].id and (cur->die > cnt or cur->die == 0)) {
          found = true;
          list[i].by = cur;
          cnt++;
          break;
        } else
          cnt = std::max(cnt, cur->die);
      }
      if (!found) cnt = 0;
    }
    maxDie = std::max(maxDie, cnt);
    list[i].die = cnt;
  }
  std::cout << maxDie;
}
