'use strict'
function main(inp) {
  let info = inp.trim().split('\n')
  let input1 = info[0].split(' ');
  let input2 = info[1];
  let K = input1[0]*1;
  let N = input1[1]*1;
  let A = input2.split(' ').map(x => x*1);
  A[N-1] = K - A[N-1];
  let ans = 0;
  for(let i = 0; i < N-2; i++){
  	ans += A[i+1] - A[i];
  }
  ans += A[N-1];
  console.log(ans);
  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
