import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt
  val x = Array.fill(N)(sc.nextInt)

  val a = x.map(x => x * 2)
  val b = x.map(x => (K - x) * 2)
  val z = (a zip b).map(x => Array(x._1, x._2).min).sum
  println(z)
}
