import java.util.*;
public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    }
} Main public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    } main {
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc sc.close() sc.close sc int maisu = 0; maisu 0 int otsuri = 0; otsuri 0 if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        } n%1000==0 n%1000 n 1000 0 {
          System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        } maisu = n / 1000 + 1 maisu n / 1000 + 1 n / 1000 n 1000 1 otsuri = maisu * 1000 - n otsuri maisu * 1000 - n maisu * 1000 maisu 1000 n System.out.println(otsuri) System.out.println System.out System System.out otsuri String[] args args public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    }
} public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      
      	int maisu = 0;
      	int otsuri = 0;
      	if(n%1000==0) {
          System.out.println(0);
        } else {
          maisu = n / 1000 + 1;
          otsuri = maisu * 1000 - n;
          System.out.println(otsuri);
        }
    }
}