'use strict';

const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const iS = () => inputs.shift();
const sMpI = (str) => str.split(' ').map(v => parseInt(v, 10));
const sMpIS = () => sMpI(iS());
const pI = v => parseInt(v);

const price = pI(iS());

console.log(price % 1000 === 0 ? 0 : 1000 - (price % 1000));