function Main(input) {
    input = parseInt(input.trim(), 10);
    while(input > 1000) {
        input -= 1000;
    }
    console.log(1000 - input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));