function Main(input) {
	input = input.split("\n");
    var result = parseInt(input) % 1000;
	if (result) {
      result = 1000 - result;
    }
	console.log('%d',result);
  	return;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));