import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	} main {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n; n n = in.nextInt() n in.nextInt() in.nextInt in int a = (n + 999) / 1000; a (n + 999) / 1000 (n + 999) n 999 1000 n = 1000 * a - n n 1000 * a - n 1000 * a 1000 a n System.out.println(n) System.out.println System.out System System.out n String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
}
