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