function Main(input) {
	let n = parseInt(input, 10);
	
	let r = n % 1000;
	if (r===0) {
	  console.log(0);
	} else {
	  console.log( 1000 - r );
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));