fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun solve(sc: java.util.Scanner) {
    val K = sc.nextInt()
    val N = sc.nextInt()
    val A = Array(N) { sc.nextInt() }

    val d = Array(N) { 0 }
    d[0] = A[0]
    for (i in 1 until N) {
        d[i] = A[i] - A[i - 1]
    }
    d[0] += K - A.last()

    println(K - d.max()!!)
}
