#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAX_N 100000+10

struct ST
{
	int size = 0;

	bool left_cal;
	bool right_cal;
};

int light[MAX_N];
int grp_size[MAX_N];

int main(void)
{
	int n;

	int grp_n = 1;

	int max_sum=0;

	int i;

	cin >> n;

	cin >> light[0];
	grp_size[1]++;

	for (i = 1; i < n; i++)
	{
		cin >> light[i];

		if (light[i] != light[i - 1])
		{
			grp_size[grp_n]++;
		}
		else
		{
			grp_n++;
			grp_size[grp_n]++;
		}
	}

	max_sum = max(grp_size[1]+ grp_size[2], grp_size[grp_n]+ grp_size[grp_n-1]);

	for (i = 1; i < grp_n; i++)
	{
		max_sum = max(max_sum, grp_size[i - 1] + grp_size[i] + grp_size[i + 1]);
	}

	cout << max_sum << endl;

	return 0;
}
