toInt :: (String -> Int)
toInt x = read x :: Int
    
main = getLine >>= putStrLn . show . calcChange . toInt

calcChange:: Int -> Int
calcChange n
 | n `mod` 1000 == 0 = 0
 | otherwise = 1000 - n `mod` 1000