import java.util.*

fun max(a: Int, b: Int): Int = if (a < b) b else a

fun main(args : Array<String>) {
    val (k, n) = readLine()!!.split(' ').map(String::toInt)
    val a = readLine()!!.split(' ').map(String::toInt)
    var d = 0
    for (i in 1 until n) {
        d = max(d, a[i] - a[i - 1])
    }
    println(k - max(d, a[0] + k - a[n - 1]))
}
