const readline = require('readline');
(async function processLineByLine() {
  const rl = readline.createInterface({
    input: process.stdin,
    crlfDelay: Infinity
  });
  for await (const line of rl) {
    let payment = Math.ceil(line / 1000) *1000;
    console.log(payment - line);
  }
})();