#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323;
const double eps = 1e-12;
const int inf = ((int)1e9) + 7;
const int MAX_N = 200;
int arr[111111];
int dp[111111];
int val[111111];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int len = 1;
  dp[0] = 0;
  val[0] = arr[0];
  for (int i = 1; i < n; i++) {
    int j;
    int cur = arr[i];
    int maxi = 0;
    for (j = len - 1; j >= 0; j--) {
      if (val[j] > cur) break;
      maxi = max(maxi, dp[j]);
    }
    dp[j + 1] = maxi;
    dp[j + 2] = maxi + 1;
    val[j + 2] = cur;
    len = j + 3;
    if (j < 0) dp[j + 2] = 0;
  }
  int ans = 0;
  for (int i = 0; i < len; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
