import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    }
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    }
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    } main {
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) double N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int pay= 1000*(int)Math.ceil(N/1000); pay 1000*(int)Math.ceil(N/1000) 1000 (int)Math.ceil(N/1000) Math.ceil Math N/1000 N 1000 System.out.println((int)(pay-N)) System.out.println System.out System System.out (int)(pay-N) pay N String[] args args public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    }
} public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    }
} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
       	double N = sc.nextInt();
      	int pay= 1000*(int)Math.ceil(N/1000);
        System.out.println((int)(pay-N));
    }
}