object Main extends App {
	val Array(k, n) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val b = new Array[Int](n)

	for(i<-0 until n-1){
		b(i) = k - (a(i+1) - a(i))
	}

	b(n-1) = a(n-1) - a(0)

	println(b.min)
}