#include <bits/stdc++.h>
using namespace std;
template <typename T>
class node {
 public:
  node<T>* next;
  node<T>* prev;
  T val;
  node(T val) {
    this->val = val;
    next = NULL;
    prev = NULL;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  node<int>* psychoPrev = NULL;
  node<int>* psychoRoot = NULL;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    node<int>* cur = new node<int>(t);
    cur->prev = psychoPrev;
    if (psychoPrev != NULL)
      psychoPrev->next = cur;
    else
      psychoRoot = cur;
    psychoPrev = cur;
  }
  node<node<int>*>* checkRoot = NULL;
  node<node<int>*>* checkPrev = NULL;
  for (node<int>* psychoNode = psychoPrev; psychoNode->prev != NULL;
       psychoNode = psychoNode->prev) {
    if (psychoNode->prev->val > psychoNode->val) {
      node<node<int>*>* checkCur = new node<node<int>*>(psychoNode->prev);
      checkCur->prev = checkPrev;
      if (checkPrev != NULL)
        checkPrev->next = checkCur;
      else
        checkRoot = checkCur;
      checkPrev = checkCur;
    }
  }
  int count = 0;
  for (; checkRoot != NULL; count++) {
    node<node<int>*>* newCheckRoot = NULL;
    node<node<int>*>* newCheckPrev = NULL;
    for (node<node<int>*>* it = checkRoot; it != NULL; it = it->next) {
      node<int>* cur = it->val;
      cur->next = cur->next->next;
      if (cur->next != NULL) cur->next->prev = cur;
      if (cur->next != NULL)
        if (cur->val > cur->next->val) {
          node<node<int>*>* checkCur = new node<node<int>*>(cur);
          checkCur->prev = newCheckPrev;
          if (newCheckPrev != NULL)
            newCheckPrev->next = checkCur;
          else
            newCheckRoot = checkCur;
          newCheckPrev = checkCur;
        }
    }
    checkRoot = newCheckRoot;
    checkPrev = newCheckPrev;
  }
  cout << count << endl;
  return 0;
}
