import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	} main {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	} Scanner kb = new Scanner(System.in); kb new Scanner(System.in) int s = kb.nextInt(); s kb.nextInt() kb.nextInt kb int p = 1000 - s % 1000; p 1000 - s % 1000 1000 s % 1000 s 1000 if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		} p == 1000 p 1000 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(p);
		} System.out.println(p) System.out.println System.out System System.out p kb.close() kb.close kb String[] args args public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	}

} public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	}

} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int s = kb.nextInt();
		int p = 1000 - s % 1000;
		if (p == 1000) {
			System.out.println(0);
		} else {
			System.out.println(p);
		}
		kb.close();
	}

}
