import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;

void main(){
    while(!stdin.eof){
        int n = readln.chomp.to!int;
        int[] a = readln().split().map!(to!int).array;
        int[] x = [0,0,0];
        foreach(i; 0..n-1){
            if(a[i] == a[i+1]){
                x ~= i+1;
            }
        }
        x ~= n;
        int ans = 0;
        foreach(i; 0..x.length-3){
            ans = max(ans, x[i+3] - x[i]);
        }
        writeln(ans);
    }
}