object Main extends App {
  val n = readInt
  //ai >= 1 としておく
  val a = readLine.split(" ").map{_.toInt + 1}
  
  val arr = Array.fill[Int](a.max+2)(0)
  
  for (i <- 0 until n) {
    arr(a(i)-1) += 1
    arr(a(i)) += 1
    arr(a(i)+1) += 1
  }
  
  val k = arr.indexOf(arr.max)
  
  var ans = 0
  ans += a.count{_ == k-1}
  ans += a.count{_ == k}
  ans += a.count{_ == k+1}
  
  println(ans)
}