#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  m = 0;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    m = max(m, A[i]);
  }
  int dp[n + 1][m + 1];
  for (int i = 0; i < n + 1; ++i) {
    for (int j = 0; j < m + 1; ++j) {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m + 1; ++j) {
      if (j) dp[i + 1][j] = max(dp[i + 1][j - 1], dp[i][j]);
      if (j >= A[i]) dp[i + 1][j] = max(dp[i][A[i] - 1] + 1, dp[i + 1][j]);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
