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