#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 7;
int a[N], dp[N][N], c1[N], c2[N], l[3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c1[i] = c1[i - 1] + (a[i] == 1);
  }
  for (int i = n; i; i--) {
    c2[i] = c2[i + 1] + (a[i] == 2);
  }
  for (int i = 1; i <= n; i++) {
    l[1] = l[2] = 0;
    for (int j = i; j <= n; j++) {
      if (a[j] == 1) {
        dp[i][j] = max(dp[i][l[1]], dp[i][l[2]]) + 1;
      } else {
        dp[i][j] = dp[i][l[2]] + 1;
      }
      l[a[j]] = j;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = max(ans, c1[i - 1] + c2[j + 1] + dp[i][j]);
    }
    ans = max(ans, c1[i] + c2[i]);
  }
  cout << ans;
  return 0;
}
