import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun solve() {
    val n = inf.readLine()!!.toInt()
    val map = TreeMap<Int, Int>()
    inf.readLine()!!.split(' ').map(String::toInt).forEach {
        map.getOrPut(it - 1, {0})
        map.put(it, map.getOrElse(it, {0}) + 1)
        map.getOrPut(it + 1, {0})
    }
    var ans = 0
    for (i in map.keys) {
        ans = Math.max(ans, map.getOrElse(i - 1, {0}) + map.getOrElse(i, {0}) + map.getOrElse(i + 1, {0}))
    }
    println(ans)
}

fun main(args: Array<String>) {
    solve()
    ouf.close()
}

val inf = BufferedReader(InputStreamReader(System.`in`))
val ouf = PrintWriter(System.out)