//'main' method must be in a class 'Rextester'.
//openjdk version '11.0.5' 

import java.util.*;
import java.lang.*;

public class Main
{  
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main
{  
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    }
} Main public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    } main {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int x =s.nextInt(); x s.nextInt() s.nextInt s if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      } x%1000==0 x%1000 x 1000 0 System.out.println(x%1000) System.out.println System.out System System.out x%1000 x 1000 {
      System.out.println(1000-x%1000);
      } System.out.println(1000-x%1000) System.out.println System.out System System.out 1000-x%1000 1000 x%1000 x 1000 String args[] args public class Main
{  
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    }
} public class Main
{  
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
      int x =s.nextInt();
      if(x%1000==0)
        System.out.println(x%1000);
      else{
      System.out.println(1000-x%1000);
      }
    }
} Main
//'main' method must be in a class 'Rextester'.
//openjdk version '11.0.5' 

import java.util.*;
import java.lang.*;

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