"use strict"
// input
function main(input) {
    const args = input.split('\n')[0];
    const a = input.split('\n')[1];
    // console.log(a);
    let as = a.split(' ');

    // const max = Math.max(...as);
    // const min = Math.min(...as);
    // console.log(max);
    // console.log(min);
    
    const K = Number(args.split(' ')[0]);
    const N = Number(args.split(' ')[1]);
    let ans = 0;
    let plus = 0;
    for (let i = 0; i < N; i++) {
        plus = Math.abs(0 - as[i]) >= Math.abs(K/2 - as[i]) ? Math.abs(K/2 - as[i]) : Math.abs(0 - as[i]);
        // console.log('plus: ' + plus);
        ans += plus;
    }
    console.log(ans);
}

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