import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt

  val a = StdIn.readLine().split(' ').map(_.toInt)
  val buff = Array.ofDim[Int](scala.math.pow(10, 5).toInt + 2)

  val max = a.foldLeft(0L) { (acc, ai) =>
    buff(ai + 1) += 1
    buff(ai) += 1
    if (ai > 0) {
      buff(ai - 1) += 1
      scala.math.max(acc, scala.math.max(buff(ai + 1), scala.math.max(buff(ai - 1), buff(ai))))
    } else {
      scala.math.max(acc, scala.math.max(buff(ai + 1), buff(ai)))
    }
  }

  //println(buff.mkString(" "))

  println(max)

}
