function main(input) {
  input=input.trim();
  var N = parseInt(input.split("\n")[0], 10);
  var K = parseInt(input.split("\n")[1], 10);
  var x = input.split('\n')[2].split(' ').map((n) => parseInt(n, 10));
  var ans=0
  for(var i=0; i<N; i++){
    var temp=Math.min.apply(null, [Math.abs(a-x[i]),Math.abs(K-x[i])])
    ans+=2*temp
  }
  console.log(ans);


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