import scala.io.StdIn._
object Main extends App{
    // val sc=new java.util.Scanner(System.in)
    val kn=readLine.split(" ").map(_.toInt)
    val k=kn(0)
    val n=kn(1)
    val a=readLine.split(" ").map(_.toInt)
    val proc=(x:Int)=>if(k/2<x)x-k/2 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)
}