import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
} import java.util.*; util.* java public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int MOD = (int)1e9 + 7; MOD (int)1e9 + 7 (int)1e9 7 final int MAX = Integer.MAX_VALUE; MAX Integer.MAX_VALUE Integer Integer.MAX_VALUE final long LMAX = Long.MAX_VALUE; LMAX Long.MAX_VALUE Long Long.MAX_VALUE int len = (int)1e7; len (int)1e7 void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	} doIt {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	} int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc System.out.println((1000-(N%1000)) % 1000) System.out.println System.out System System.out (1000-(N%1000)) % 1000 (1000-(N%1000)) 1000 (N%1000) N 1000 1000 public static void main(String[] args) {
		new Main().doIt();
	} main {
		new Main().doIt();
	} new Main().doIt() new Main().doIt new Main() String[] args args public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
} public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
} Main
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		int N = sc.nextInt();
		System.out.println((1000-(N%1000)) % 1000);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
}