object Main extends App{
    val sc=new java.util.Scanner(System.in)
    val k,n=sc.nextInt
    val y=k/2
    val a=List.fill(n)(sc.nextInt)
    val proc=(x:Int)=>if(y<x)x-y else x
    val p=(proc(a.last-a.head))::(1 until n).map(i=>proc(a(i)-a(i-1))).toList
    println(k-p.max)
}