#include <bits/stdc++.h>
using namespace std;
int n, a[2001], b[2001], d[2001], asc[2001], desc[2001], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[n - i - 1] = a[i];
  }
  for (int i = 0; i < n; i++) {
    d[i] = asc[i] = 1;
    for (int j = 0; j < i; j++) {
      if (a[i] < a[j]) continue;
      d[i] = max(d[i], d[j] + 1);
      asc[i] = max(asc[i - 1], d[i]);
    }
  }
  memset(d, 0, sizeof(d));
  for (int i = 0; i < n; i++) {
    d[i] = desc[i] = 1;
    for (int j = 0; j < i; j++) {
      if (b[i] > b[j]) continue;
      d[i] = max(d[i], d[j] + 1);
      desc[i] = max(desc[i - 1], d[i]);
    }
  }
  for (int i = 0; i < n; i++) ans = max(ans, asc[i] + desc[n - i - 2]);
  cout << ans;
}
