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