import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInteger
getInt = readInt <$> BS.getLine

solve n
  | n `mod` 1000 == 0 = 0
  | otherwise         = 1000 - n `mod` 1000

main = do
  n <- getInt
  print $ solve n
