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