main = do
  str <- getLine
  let [n, k] = map read (words str) ::[Int]
  print $ ck n k


ck :: Int -> Int -> Int
ck n k 
  | n `mod` k == 0                 = 0
  | k - (n `mod` k) <= (n `mod` k) = k - (n `mod` k)
  | otherwise                      = n `mod` k