import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextLong()
    val n = sc.nextLong()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem160c(k, n, a))
}

fun problem160c(k: Long, n: Long, a: List<Long>): Long {
    var maxDiff = 0L
    var acc = 0L
    for (i in 0 until a.size - 1) {
        val diff = a[i+1] - a[i]
        maxDiff = Math.max(maxDiff, diff)
        acc += diff
    }
    maxDiff = Math.max(maxDiff, k - acc)
    return k - maxDiff
}
