#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
vector<char*> tokenizer(const char* args) {
  char* token = new char[111];
  strcpy(token, args);
  token = strtok(token, ", ");
  vector<char*> v({token});
  while (token = strtok(NULL, ", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << " "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << "[" << args.back() << ": " << H << "] ";
  args.pop_back();
  debugg(args, T...);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    stack<pair<long long, long long>> stk;
    long long cnt = 0, ans = 0;
    for (long long i = 0; i < n; i++) {
      long long tmp;
      cin >> tmp;
      cnt = 0;
      while (stk.size() > 0 and stk.top().first < tmp) {
        cnt = max(cnt, stk.top().second);
        stk.pop();
      }
      if (stk.size() == 0) {
        stk.push({tmp, 1e9});
      } else {
        ans = max(ans, cnt + 1);
        stk.push({tmp, cnt + 1});
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
