'use strict';

function Main(input) {
    const N = Number(input.trim().split('\n')[0]);

    const bill = Math.ceil(N / 1000);

    console.log(bill * 1000 - N);

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));