object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	val lines = readInt;
  	val k = readInt;
  	val balls = readLine.split(" ").map(_.toInt).toList
  
  	println(balls.map(x => List(x,scala.math.abs(k-x)).min.*(2)).sum.toString)   
}