#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair

using namespace std;

int n, a[2005], tmp[2005], upto[2005], post[2005], t = 0;

pii arr[2005];

void print(){
    for(int j = 0; j < t; j++)
        cout << "(" << arr[j].first << " " << arr[j].second << ")  ";
    cout << endl;
}

int rev(int l, int r){
    for(int j = 0; j < n; j++)
        tmp[j] = a[j];
    for(int j = l; j <= (r + l)/2; j++)
        swap(tmp[j], tmp[r + l - j]);

    t = 0;
    for(int j = 0; j < n; j++){
        int c = tmp[j], cnt = 0;
        while(j < n && c == tmp[j]) cnt++, j++;
        j--;
        arr[t++] = mp(c, cnt);
    }
    //print();

    int ans = 0;
    upto[t] = 0;
    upto[t-1] = arr[t-1].second;
    ans = upto[t-1];
    for(int j = t-2; j >= 0; j--){
        int cur = arr[j].second;
        if(arr[j].first == 1) upto[j] = max(upto[j+2]+cur, upto[j+1]+cur);
        else upto[j] = cur + upto[j+2];
        if(ans < upto[j]) ans = upto[j];
    }
    //cout << l << " " << r << " " << ans << endl;
    return ans;
}

int main(){
    scanf("%d",&n);
    for(int j = 0; j < n; j++)
        scanf("%d",&a[j]);
    int ans = rev(0, 0);

    for(int j = 0; j < n; j++){
        for(int k = j+1; k < n; k++){
            ans = max(ans, rev(j, k));
        }
    }
    printf("%d\n",ans);
    return 0;
}