import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      } main {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str=sc.nextLine(); str sc.nextLine() sc.nextLine sc int a =Integer.parseInt(str); a Integer.parseInt(str) Integer.parseInt Integer str if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       } a%1000==0 a%1000 a 1000 0 {
          System.out.println(0);} System.out.println(0) System.out.println System.out System System.out 0 if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       } a%1000>0 a%1000 a 1000 0 {
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       } int z=1; z 1 int b= a/1000; b a/1000 a 1000 System.out.println((z+b)*1000-a) System.out.println System.out System System.out (z+b)*1000-a (z+b)*1000 (z+b) z b 1000 a String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	}