min' :: Int -> Int -> Int
min' l m = if l <= m then l else m

solve :: Int -> Int -> Int
solve n k | modulo == 0 = 0
          | otherwise   = min' modulo (abs (modulo - k))
    where modulo = n `mod` k

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