import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  }
} Main public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int a = stdIn.nextInt(); a stdIn.nextInt() stdIn.nextInt stdIn if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000); a % 1000 == 0 a % 1000 a 1000 0 System.out.print(0) System.out.print System.out System System.out 0 if(a % 1000 != 0)
      System.out.print(1000 - a % 1000); a % 1000 != 0 a % 1000 a 1000 0 System.out.print(1000 - a % 1000) System.out.print System.out System System.out 1000 - a % 1000 1000 a % 1000 a 1000 String[] args args public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  }
} public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
   
    if(a % 1000 == 0)
    System.out.print(0);
    
    else if(a % 1000 != 0)
      System.out.print(1000 - a % 1000);
  }
}