import java.util.Scanner;

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

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      
      int n = N / 1000;
      if(N % 1000 != 0){
        n++;
      }
      System.out.println(n * 1000 - N);
    
    }
}