#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int N;
int light[100005];
int dp[3][100005] = {};
int main() {
	cin >> N;
	rep(i, N) cin >> light[i];
	for (int i = 1; i < N; i++) {
		if (light[i - 1] != light[i]) {
			dp[0][i] = dp[0][i - 1] + 1;
			dp[1][i] = dp[1][i - 1] + 1;
			dp[2][i] = dp[2][i - 1] + 1;
		}
		else
		{
			dp[1][i] = dp[0][i - 1] + 1;
			dp[2][i] = dp[1][i - 1] + 1;
		}
	}
	int ans = 0;
	rep(i, 3)rep(j, N) ans = max(ans, dp[i][j]);
	cout << ans+1 << endl;

	return 0;
}
