function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = parseInt(input.split("\n")[0]);
  
    if (input % 1000 == 0) console.log(0);
    else console.log(1000 - (input % 1000));
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));