function Main(arg) {
  let n = Number(arg.trim());
  if(n%1000 == 0){
    console.log(0);
    return;
  }
  let pay = 0;
  while(pay < n){
    pay+=1000;
  }
  console.log(pay-n);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));