function Main (input) {
  input = input.split("\n").map(inp => inp.split(" ").map(Number));
  var K = input[0][0];
  var N = input[0][1];
  var A = input[1];
  var sr_lo = [A[0] + (K-A[N-1])];
  for (var i = 0; i < N-1; i++) {
    sr_lo.push(A[i+1] - A[i]);
  }
  console.log(K - Math.max(...sr_lo));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));