function Main(input) {
    tmp = input.split(" ");
    n = parseInt(tmp[0], 10);
    pay = Math.ceil((n / 1000));    
    result = (pay * 1000) - n;
    console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));