import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	} main {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int  n = in.nextInt(); n in.nextInt() in.nextInt in int  rem = n%1000; rem n%1000 n 1000 if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				} n%1000==0 n%1000 n 1000 0 {
			System.out.println(0);
			} System.out.println(0) System.out.println System.out System System.out 0 {
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				} int div = n/1000+1; div n/1000+1 n/1000 n 1000 1 int ans= div*1000 - n; ans div*1000 - n div*1000 div 1000 n System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int  n = in.nextInt();
		int  rem = n%1000;
	//	int div = n%1000;
		if(n%1000==0){
			System.out.println(0);
			}
			else{
				int div = n/1000+1;
				int ans= div*1000 - n;
					System.out.println(ans);
				}
	
	}
}