#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    int A[100005];
    vector < int > data;
    int cnt = 0;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i > 0 && A[i] == A[i - 1]) {
            data.push_back(cnt);
            cnt = 1;
        } else {
            cnt++;
        }
    }
    data.push_back(cnt);
    int maxv = 0;
    int sum = 0;
    for(int i = 0; i < data.size(); i++) {
        sum += data[i];
        if(i >= 3) sum -= data[i - 3];
        maxv = max(maxv, sum);
    }
    cout << maxv << endl;
    return (0);
}
