function main(K, N, A) {
  const area = [];

  let c = 0;

  for (let i = 0; i < N; i++) {
    area.push(parseInt(A[i]) - c);

    c = A[i];
  }

  area.push(K - c);

  area.sort((a, b) => a - b);

  let res = 0;

  for (let i = 0; i < N - 1; i++) {
    res += parseInt(A[i]);
  }

  console.log(res);
}


const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');

const K = parseInt(input[0].split(' ')[0]);
const N = parseInt(input[0].split(' ')[1]);
const A = input[1].split(' ');

main(K, N, A);
