const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const data = Buffer.concat(chunks).toString("utf8").trim();
  const N = parseInt(data, 10);
  console.log(solve(N));
});

function solve(N) {
  const mod = N % 1000;
  if (mod === 0) return 0;
  return 1000 - mod;
}
