#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N;
bool num[100000];
vector<int>l;
int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++)cin >> num[i];
	l.push_back(-1);
	for (int i = 0; i < N - 1; i++) {
		if (num[i] == num[i + 1])l.push_back(i);
	}
	l.push_back(N-1);
	
	int box = -1;
	for (int i = 1; i < l.size() - 2; i++) {
		ans = max(ans, l[i + 2] - l[i - 1]);
	}
	if (!ans)ans = N;
	cout << ans << endl;
	return 0;
}