fun main(args: Array<String>) {
    val (k, t) = readLine()!!.split(' ').map(String::toInt)
    val a = readLine()!!.split(' ').map(String::toInt).sorted()
    val mx = a[t - 1]
    println(Math.max(0, k - 1 - 2 * (k - mx)))
}