import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
} import java.io.*; io.* java import java.util.*; util.* java import java.awt.Point; Point java.awt public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
} Main static Scanner sc; sc static PrintWriter out; out static final int uncal = -1; uncal -1 1 static final int mod = (int) (1e9)+7; mod (int) (1e9)+7 (int) (1e9) 7 public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	} main {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	} sc = new Scanner(System.in) sc new Scanner(System.in) out = new PrintWriter(System.out) out new PrintWriter(System.out) int n = sc.nextInt()%1000; n sc.nextInt()%1000 sc.nextInt() sc.nextInt sc 1000 if(n > 0)
			n = 1000-n; n > 0 n 0 n = 1000-n n 1000-n 1000 n out.println(n) out.println out n out.close() out.close out String[] args args public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
} public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
} Main
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
}