function *main() {
  let n = Number(yield);
  for(let i=1; i<=10; i++){
    if(n<=i*1000){
      console.log(i*1000-n);
      return;
    }
  }
}
const iter = main();
iter.next();
require("readline").createInterface(
  {input: process.stdin, output: process.stdout}
).on("line", line => iter.next(line));