#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
inline long long getPow(long long a, long long b) {
  long long res = 1, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
    }
    tp *= tp;
    b >>= 1ll;
  }
  return res;
}
inline long long to_ll(string s) {
  long long cur = 0;
  for (int i = 0; i < s.size(); i++) {
    cur = cur * 10 + s[i] - '0';
  }
  return cur;
}
inline string to_str(long long x) {
  string s = "";
  while (x) {
    s += char(x % 10 + '0');
    x /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
inline long long nxt() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
int main() {
  long long n = nxt();
  vector<long long> buf_1(n + 1, 0);
  vector<long long> buf_2(n + 1, 0);
  vector<long long> mas(n);
  for (int i = 0; i < n; i++) {
    mas[i] = nxt();
    buf_1[i + 1] = buf_1[i];
    buf_2[i + 1] = buf_2[i];
    if (mas[i] == 1) {
      buf_1[i + 1]++;
    } else {
      buf_2[i + 1]++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, buf_1[i] + buf_2[n] - buf_2[i]);
  }
  for (int r = 0; r < n; r++) {
    long long cur = 0;
    for (int l = r; l >= 0; l--) {
      if (mas[l] == 2) {
        cur++;
      }
      cur = max(cur, buf_1[r + 1] - buf_1[l]);
      ans = max(ans, cur + buf_1[l] - buf_2[r + 1] + buf_2[n]);
    }
  }
  cout << ans;
  return 0;
}
