import java.util.*;
class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    }
} import java.util.*; util.* java class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    }
} Main public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    } main {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int rem = n%1000; rem n%1000 n 1000 if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem); rem==0 rem 0 System.out.println(rem) System.out.println System.out System System.out rem System.out.println(1000-rem) System.out.println System.out System System.out 1000-rem 1000 rem String args[] args
import java.util.*;
class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int rem = n%1000;
      if(rem==0)
        System.out.println(rem);
      else
        System.out.println(1000-rem);
    
    }
}