function Main(input) {
	var N = parseInt(input, 10);
	var warizan = N/1000;
  	var oturi = N - 1000*Math.floor(warizan);
	//出力
	console.log(oturi);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));