module Main where

import qualified Data.Vector as V
import           Data.List
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  n <- getLine
  k <- readLn
  xs <- sort . map read . words <$> getLine
  print $ f xs k 0

f [] _ d = d
f (x:xs) k d = f xs k d + min (2 * x) (2 * (k - x))