#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
T read() {
  char c = getchar();
  T sgn = 1;
  T t = 0;
  while (!isdigit(c)) {
    if (c == '-') sgn = -sgn;
    c = getchar();
  }
  while (isdigit(c)) {
    t *= 10;
    t += c - '0';
    c = getchar();
  }
  return t * sgn;
}
struct node {
  int id, val;
  node(int x, int y) : id(x), val(y) {}
};
const int N = 1e5 + 233;
int t[N], a[N];
stack<node> s;
int main() {
  int n = read<int>();
  for (int i = 0; i < n; ++i) a[i] = read<int>();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    node temp(0, 0);
    int sumn = 0;
    while (!s.empty()) {
      temp = s.top();
      if (temp.id < a[i]) {
        sumn = max(sumn, temp.val);
        s.pop();
      } else
        break;
    }
    if (s.empty())
      s.emplace(a[i], 0);
    else
      s.emplace(a[i], sumn + 1);
    ans = max(s.top().val, ans);
  }
  printf("%d\n", ans);
  return 0;
}
