#include <iostream>
#include <vector>
#include <string>
#define N 100000

using namespace std;

int main(){
        int n;
        cin>>n;
        string line;
        cin.ignore();
        getline(cin,line);

        int sum[N] = { -1 };
        int write = 1;
        int before = line.c_str()[0] - '0';

        for(int i = 1;i < n;i++){
                if( before - (line.c_str()[2*i] - '0') == 0 ){
                        sum[ write++ ] = i - 1;
                }
                before = line.c_str()[2*i] - '0';
        }
        sum[ write++ ] = n-1;

        int max_size = 0;
        if(write <= 3){
                max_size = n;
        }else{
                for(int i = 3;i < write ;i++){
                        max_size = std::max( max_size, sum[i] - sum[i - 3]);
                }
        }
        cout<<max_size<<endl;
        return 0;
}