import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	val n = scn.nextInt()
	val a0 = scn.nextInt()
	var bef = a0
	var max = 0
	for (i in 2..n){
		val a = scn.nextInt()
		max = (a - bef).coerceAtLeast(max)
		bef = a
	}
	max = (k+a0-bef).coerceAtLeast(max)
	println(k-max)
}