#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &e : a) cin >> e;
  for (int &e : a)
    if (e & 1)
      e = -1;
    else
      e = 1;
  vector<int> l[n], r[n];
  for (int i = 0; i < n; i++) {
    l[i].resize(n - i, a[i]);
    for (int j = 1; j + i < n; j++) l[i][j] = l[i][j - 1] + a[j + i];
  }
  for (int i = n - 1; i >= 0; i--) {
    r[i].resize(i + 1, a[i]);
    for (int j = 1; i - j >= 0; j++) r[i][j] = r[i][j - 1] + a[i - j];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int temp = 0;
    int lm = 0;
    int rm = 0;
    if (i > 0) {
      int ori = r[i - 1].back();
      ori = (i - abs(ori)) / 2;
      ori -= min(0, r[i - 1].back());
      lm = ori;
      for (int j = 0; i - 1 - j >= 0; j++) lm = max(ori + r[i - 1][j], lm);
    }
    if (i < n) {
      int ori = l[i].back();
      ori = (n - i - abs(ori)) / 2;
      ori += max(0, l[i].back());
      rm = ori;
      for (int j = 0; j + i < n; j++) rm = max(ori - l[i][j], rm);
    }
    temp = lm + rm;
    ans = max(temp, ans);
  }
  cout << ans;
  cin >> n;
}
