object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val hashMap = scala.collection.mutable.HashMap.empty[Int, Int]
  (1 to N).foreach { _ =>
    val a = sc.nextInt()
    hashMap.update(a, hashMap.getOrElse(a, 0) + 1)
  }
  val max = hashMap.foldLeft(0) { case (acc, (a, count)) =>
    acc.max(hashMap.getOrElse(a - 1, 0) + count + hashMap.getOrElse(a + 1, 0))
  }
  println(max)
}
