// https://atcoder.jp/contests/abc173/tasks/abc173_a

const main = (args) => {
  const [N] = args[0].split(' ').map(Number);
  const x = N % 1000;
  
  console.log(x ? 1000-x: 0);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'));
