main = (input) => {
  const price  = parseInt(input.trim(), 10)
  const pay    = (Math.ceil(price / 1000)) * 1000
  const result = pay - price
  console.log(result)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));