import Control.Monad (replicateM) import Data.List (sort) solve :: Integer -> Int -> [Integer] -> Integer solve b n cs = sum $ map (abs . (\x -> mi - x)) cs where ave = (b + sum cs) `div` n' mid = (cs !! ((n - 1) `div` 2) + cs !! (n `div` 2)) `div` 2 mi = min ave mid n' = fromIntegral n :: Integer main = do b <- readLn :: IO Integer n <- readLn :: IO Int cs <- sort . map read <$> replicateM n getLine :: IO [Integer] print $ solve b n cs