#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N], n, i, k, j, c, p, b[N], m, r, t, check, mr;
struct tree {
  int data = 0;
  int rank = 1;
} * ROOT[N], *f[N];
vector<int> leafs;
void push(tree*& node, int number) {
  tree* child = new tree();
  child->data = number;
  child->rank = node->rank + 1;
  f[number] = child;
  if (leafs.size()) {
    for (int it = leafs.size() - 1; it >= 0; it--) {
      if (leafs[it] == node->data) {
        leafs.erase(leafs.begin() + it);
        break;
      }
    }
  }
  leafs.push_back(number);
  c = max(c, child->rank);
};
int main() {
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    if (a[i] > m) {
      j++;
      ROOT[j] = new tree();
      ROOT[j]->data = a[i];
      m = a[i];
      if (leafs.size()) leafs.clear();
      continue;
    }
    if (a[i] > a[i - 1]) {
      if (!leafs.size()) {
        push(ROOT[j], a[i]);
        continue;
      } else {
        r = 0;
        mr = 0;
        check = 0;
        for (int it = leafs.size() - 1; it >= 0; it--) {
          if (f[leafs[it]]->rank < r) leafs.erase(leafs.begin() + it);
          if (mr <= f[leafs[it]]->rank) {
            if (leafs[it] < a[i]) {
              if (f[leafs[it]]->rank > r) {
                r = f[leafs[it]]->rank;
                t = leafs[it];
                check = 1;
              }
            }
          }
          mr = max(mr, f[leafs[it]]->rank);
        }
        if (check)
          push(f[t], a[i]);
        else
          push(ROOT[j], a[i]);
      }
    } else {
      c = max(c, 1);
    }
  }
  if (c)
    cout << c;
  else
    cout << 0;
}
