function Main(inputs) {
	const inputline = inputs.split("\n");
	const N = parseInt(inputline[0], 10);
	const divisionK = N/1000;
  	let change = N - 1000*(Math.floor(divisionK));
	console.log(change);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));