import java.lang.Math.max

fun main(args: Array<String>) {
    val (K, N) = readLine()!!.split(" ").map(String::toInt)
    val houseList = readLine()!!.split(" ").map(String::toInt).toMutableList()
    houseList.add(houseList.first() + K)
    var m = 0
    for (i in 0 until (houseList.size - 1)) {
        m = m.coerceAtLeast(houseList[i + 1] - houseList[i])
    }

    println(K - m)
}
