const processData = (lines) => {
    const n = +lines[0]
    console.log(1000 - n%1000 < 1000 ? 1000 - n % 1000 :  0)
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    processData(lines)
})
