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

using namespace std;


int N;
int l[100001];
int dp[100001][3] = {};

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> l[i];
	}

	dp[1][0] = 1;
	dp[1][1] = 1;
	dp[1][2] = 1;

	for (int i = 2; i <= N; i++) {
		if (l[i] != l[i-1]) {
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			dp[i][2] = dp[i - 1][2] + 1;
		}
		else {
			dp[i][0] = 1;
			dp[i][1] = dp[i - 1][0] + 1;
			dp[i][2] = dp[i - 1][1] + 1;
		}
	}

	int ans = 0;
	for (int i = 2; i <= N; i++) {
		for (int j = 0; j < 3; j++) {
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;


	return 0;
}


