function A173(_input) {
    var lines = _input.split("\n");
    var num = parseInt(lines[0], 10);
    var r = num % 1000;

    if (r === 0) {
        console.log(0);
    } else {
        console.log(1000 - r);
    }
}
A173(require("fs").readFileSync("/dev/stdin", "utf8"));
