import java.util.*

fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val lamps = readLine()!!.trim().split(' ').map(String::toInt)
    var length = 1
    val stack = Stack<Int>()
    for (i in 1 until n){
        if (lamps[i] == lamps[i - 1]) {
            stack.push(length)
            length = 1
        }else{
            length++
        }
    }
    stack.push(length)
    val len = stack.toIntArray()
    println(if (len.size > 2) (1 until len.size - 1).map{len[it - 1] + len[it] + len[it + 1]}.max()!! else n)
}
