"use strict";
function main(input) {
  let kari = input[0].trim().split(" ").map(i => parseInt(i));
  let k = kari[0];
  let n = kari[1];

  let a = input[1].trim().split(" ").map(i => parseInt(i));

  let b = [];
  b[0] = 0;
  for(let i=1;i<n;i++){
    b[i] = a[i] - a[i-1];
  }
  b[n] = a[0] + (k - a[n-1]);
  //console.log(b);
  
  b.sort(function(a, b) {
    return b - a;
  });

  let sum = 0;

  for(let i=1;i<b.length;i++){
    sum += b[i];
  }

  console.log(sum)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));