import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

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

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {

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

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

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

} public class Main {

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

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

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

}
