#include <bits/stdc++.h>
using namespace std;
const int INF = 999999999;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int dp[n][n];
  for (int i = 0; i < n; i++) dp[i][0] = INF;
  for (int i = 1; i < n; i++) {
    for (int j = i - 1; j < n; j++) dp[j][i] = INF;
  }
  dp[0][0] = a[0];
  for (int i = 1; i < n; i++) dp[i][0] = min(dp[i - 1][0], a[i]);
  int ans;
  for (int j = 1; j < n; j++) {
    for (int i = j; i < n; i++) {
      if (a[i] > dp[i - 1][j - 1])
        dp[i][j] = min(dp[i - 1][j], a[i]);
      else
        dp[i][j] = dp[i - 1][j];
    }
    if (dp[n - 1][j] == INF) {
      ans = j;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
