import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
} Main public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	} main {
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	} Scanner in = new java.util.Scanner(System.in); in new java.util.Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int m = n%1000; m n%1000 n 1000 if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		} m == 0 m 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(1000 - m);
		} System.out.println(1000 - m) System.out.println System.out System System.out 1000 - m 1000 m in.close() in.close in String[] args args public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
} public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
}
