import java.util.Scanner;

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int x = N/1000;
		int y = 0;
		if (N%1000 != 0) {
			y = 1000*(x+1) - N;
		} else {
			y = 1000*x - N;
		}
		System.out.println(y);
	}
}
