import java.lang.Math.min
import java.lang.Math.abs

fun main(args: Array<String>) = ABC160C.main()

object ABC160C {
    fun log(message: Any?) {
        //println(message)// TODO: ←消す
    }

    val K: Int
    val N: Int
    val A: List<Int>    // 0-origin

    init {
        val (k, n) = readInts()
        K = k
        N = n
        A = readInts()

    }

    fun main() {
        val ans = (0 until N).map {
            dist(it)
        }.min()
        println(ans)
    }

    fun dist(i: Int): Int {
        val toIp = if (i < N - 1) abs(A[i + 1] - A[i]) else abs(A.first() + (K - A.last()))
        val toIm = if (0 < i) abs(A[i] - A[i - 1]) else abs(A.first() + (K - A.last()))
        val right = K - toIp
        val left = K - toIm

        log("$right, $left")
        return min(right, left)
    }

    /*####################################################################################*/

    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}