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

public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
}
      
   
     import java.util.*; util.* java import java.util.Scanner; Scanner java.util import java.lang.*; lang.* java public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
} Main public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  } main {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  } try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    } catch(Exception e)
    {
      return ;
    } Exception e {
      return ;
    } return ; {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    } int n n rem=0 rem 0 res=0; res 0 Scanner s=new Scanner(System.in); s new Scanner(System.in) n=s.nextInt() n s.nextInt() s.nextInt s rem=n%1000 rem n%1000 n 1000 if(rem!=0)
    {
       res=1000-rem;
    } rem!=0 rem 0 {
       res=1000-rem;
    } res=1000-rem res 1000-rem 1000 rem System.out.println(res) System.out.println System.out System System.out res String args[] args public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
} public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
} Main
import java.util.*;
import java.util.Scanner;
import java.lang.*;

public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
}
      
   
    