//package project1;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main {
      public static void main(String args[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      }
} import java.io.*; io.* java import java.math.*; math.* java import java.security.*; security.* java import java.text.*; text.* java import java.util.*; util.* java import java.util.concurrent.*; concurrent.* java.util import java.util.function.*; function.* java.util import java.util.regex.*; regex.* java.util import java.util.stream.*; stream.* java.util import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList; public class Main {
      public static void main(String args[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      }
} Main public static void main(String args[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      } main {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int res = (1000-(n%1000))%1000; res (1000-(n%1000))%1000 (1000-(n%1000)) 1000 (n%1000) n 1000 1000 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[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      }
} public class Main {
      public static void main(String args[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      }
} Main
//package project1;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main {
      public static void main(String args[]) {
    	  Scanner sc = new Scanner(System.in);
    			  int n = sc.nextInt();
    	  int res = (1000-(n%1000))%1000;
    	  System.out.println(res);
      }
}
