"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const N = parseInt(inputList[0].split(" ")[0]);

    const change = N % 1000;

    if (change === 0) {
        console.log(0);
    } else {
        console.log(1000 - change)
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));