function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ')
  if (N % 1000 === 0) {
    console.log(0)
  } else {
    console.log(
      (1000 - (N % 1000))
    )
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())
