main = getContents >>= print . solve . map read . lines solve :: [Integer] -> Integer solve [n, m] = a - mod a 1000 where a = div n m