import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	}

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	} main {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	} try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		} {

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int oturi= 0; oturi 0 if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			} N%1000!=0 N%1000 N 1000 0 {
				System.out.println(1000-N%1000);
			} System.out.println(1000-N%1000) System.out.println System.out System System.out 1000-N%1000 1000 N%1000 N 1000 {
				System.out.println(0);
			} System.out.println(0) System.out.println System.out System System.out 0 String[]args args public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	}

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int oturi= 0;


			if(N%1000!=0) {
				System.out.println(1000-N%1000);
			}else {
				System.out.println(0);
			}
			

			

		}

	}

}