import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	}

} import java.util.*; util.* java import java.io.*; io.* java public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		} 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 y = n%1000;
			System.out.println(1000-y);
		} int y = n%1000; y n%1000 n 1000 System.out.println(1000-y) System.out.println System.out System System.out 1000-y 1000 y String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	}

} Main
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%1000==0) {
			System.out.println("0");
		}
		else {
			int y = n%1000;
			System.out.println(1000-y);
		}
	}

}