#include
#include
#include
using namespace std;
int main() {
int n;
cin >> n;
int niza[n];
for(int i = 0; i < n; i++) {
cin >> niza[i];
}
int i = 0, j = 0;
int cnt_3 = 0;
int res = 0;
while(j < n) {
if(cnt_3 <= 3) {
if(niza[j] == 3) {
cnt_3++;
}
j++;
}
else {
if(niza[i] == 3) {
cnt_3--;
}
i++;
}
if(cnt_3 == 3) {
res = max(res, j - i);
}
}
cout << res << endl;
return 0;
}