#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int main()
{
	int n; scanf("%d", &n);

	vector<int> r(n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &r[i]);

		if (i % 2) { r[i] ^= 1; } // Reverse
	}

	vector<int> compress; compress.push_back(0);

	for (int i = 1; i < n; i++)
	{
		if (r[i - 1] != r[i])
		{
			compress.push_back(i);
		}
	}

	compress.push_back(n);

	int ret = 0;
	
	if (compress.size() <= 3)
	{
		ret = n;
	}
	else
	{
		for (int i = 0; i < compress.size() - 3; i++)
		{
			ret = max(ret, compress[i + 3] - compress[i]);
		}
	}

	printf("%d\n", ret);

	return 0;
}