#include <bits/stdc++.h>
using namespace std;
int dp[2100][4];
int m, n, c, a[8100];
int main() {
  cin >> m;
  for (int x = 1; x <= m; x++) {
    cin >> a[x];
  }
  for (int x = 1; x <= m; x++) {
    if (a[x] == 1) {
      dp[x][0] = dp[x - 1][0] + 1;
      dp[x][1] = dp[x - 1][1];
      dp[x][2] = max(dp[x - 1][1], dp[x - 1][2]) + 1;
      dp[x][3] = dp[x - 1][3];
    } else {
      dp[x][0] = dp[x - 1][0];
      dp[x][1] = max(dp[x - 1][1], dp[x - 1][0]) + 1;
      dp[x][2] = dp[x - 1][2];
      dp[x][3] = max(dp[x - 1][3], dp[x - 1][2]) + 1;
    }
  }
  cout << max(dp[m][0], max(dp[m][1], max(dp[m][2], dp[m][3]))) << endl;
}
