#include <bits/stdc++.h>
using namespace std;
template <class T>
T cross(complex<T> a, complex<T> b) {
  return imag(a * conj(b));
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void setmax(T &a, T b) {
  if (b > a) a = b;
}
const int MAXN = 200000, L = 1 << 14;
int N;
stack<pair<int, int> > values;
vector<pair<int, int> > maxTimes;
int size[2 * L];
int minVal[2 * L];
void io(istream &in, ostream &out) {
  in >> N;
  int curMax = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int v;
    in >> v;
    while (!values.empty() && values.top().first < v) values.pop();
    int t = 0;
    if (!values.empty()) {
      int prev = values.top().second;
      if (prev + 1 == i)
        t = 1;
      else
        t = lower_bound(maxTimes.begin(), maxTimes.end(),
                        pair<int, int>(prev + 1, 0))
                ->second +
            1;
    }
    while (!maxTimes.empty() && maxTimes.back().second <= t)
      maxTimes.pop_back();
    maxTimes.push_back(pair<int, int>(i, t));
    values.push(pair<int, int>(v, i));
    setmax(ans, t);
  }
  out << ans << '\n';
}
int main() {
  ifstream fin("B.in");
  if (fin.good()) {
    ofstream fout("B.out");
    io(fin, fout);
    fin.close();
    fout.close();
  } else
    io(cin, cout);
  return 0;
}
