process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (input) => {
  const N = Number(input);
  const a = N % 1000;
  const result = a ? 1000 - a : a ;
  console.log(result);
});
