fun main(args :Array<String>){
  var input : String? = readLine()
  var param = input!!.split(" ")
  var total = param[0].toInt()
  var houses = param[1].toInt()
  var input2 : String? = readLine()
  var len = input2!!.split(" ")
  var max = 0
  var now = 0
  for(i in 1 until houses){
    now = len[i].toInt() - len[i-1].toInt()
    if(max < now){
      max = now
    }
  }
  now = total + len[0].toInt() - len[len.lastIndex].toInt()
  if(max < now ) max = now 
  println(total - max)
}