import java.util.Scanner;

public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  }
} Main public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  } main {
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer cost = sc.nextInt(); cost sc.nextInt() sc.nextInt sc Double d = Math.ceil(cost/1000.0); d Math.ceil(cost/1000.0) Math.ceil Math cost/1000.0 cost 1000.0 System.out.println(new Double((d*1000)-cost).intValue()) System.out.println System.out System System.out new Double((d*1000)-cost).intValue() new Double((d*1000)-cost).intValue new Double((d*1000)-cost) String[] args args public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  }
} public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    Integer cost = sc.nextInt();
    Double d = Math.ceil(cost/1000.0);
   
    System.out.println(new Double((d*1000)-cost).intValue());
  }
}