import java.util.Scanner;

public class Main {

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

} import java.util.Scanner; Scanner java.util public class Main {

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

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

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

} public class Main {

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

} Main
import java.util.Scanner;

public class Main {

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

}
