#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	bool *patern[2];
	bool dotti=false;
	int N;
	cin >> N;
	for (int i = 0; i < 2; ++i) {
		patern[i] = new bool[N];
	}
	for (int i = 0; i < N; ++i) {
		cin >> patern[0][i];
		if (dotti)patern[0][i] = !patern[0][i];
		dotti = !dotti;
		patern[1][i] = !patern[0][i];
	}
	vector<int> line;
	int count;
	bool now;
	int answer = 0;
	for (int i = 0; i < 2; ++i) {
		count = 0;
		if (patern[i][0] == false) {
			line.push_back(0);
			now = false;
		}
		else {
			now = true;
		}
		for (int j = 0; j < N; ++j) {
			if (patern[i][j] == now) {
				++count;
			}
			else {
				line.push_back(count);
				count = 1;
				now = !now;
			}
		}
		line.push_back(count);
		if (line.size() >= 3) {
			for (int j = 0; j < line.size() - 2; j += 2) {
				answer = max(line[j] + line[j + 1] + line[j + 2], answer);
			}
		}
		else {
			answer = max(answer, (line.size() == 2 ? line[0] + line[1] : line[0]));
		}
		line.clear();
	}
	cout << answer << endl;
	return 0;
}