#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int ill[100001]={0};
    int ren[100001]={0};
    int n,count=0;
    int ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ill[i];
        if(i==0||ill[i-1]!=ill[i]){
            ren[count]++;
        }
        else{
            count++;
            ren[count]++;
        }
    }
    ans=max(ren[0]+ren[1],ren[count]+ren[count-1]);
    for(int i=1;i<=count-1;i++){
        ans=max(ans,ren[i-1]+ren[i]+ren[i+1]);
    }
    if(count==1)cout<<n<<endl;
    else cout<<ans<<endl;
    
}

