import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    }

} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      } int i = 1; int i = 1; i 1 i <= 10 i 10 i++ i++ i {
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      } {
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      } if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        } (n - 1000 * i) <= 0 (n - 1000 * i) n 1000 * i 1000 i 0 {
          System.out.println((n - 1000 * i) * -1);
          break;
        } System.out.println((n - 1000 * i) * -1) System.out.println System.out System System.out (n - 1000 * i) * -1 (n - 1000 * i) n 1000 * i 1000 i -1 1 break; String[] args args public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    }

} public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    }

} Main
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      for(int i = 1; i <= 10; i++){
        if((n - 1000 * i) <= 0){
          System.out.println((n - 1000 * i) * -1);
          break;
        }
      }
    }

}