import java.util.*;

class Main {
  static Scanner sc = new Scanner(System.in);

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

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

class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int n = sc.nextInt();
    int x = n % 1000;
    if (x > 0) {
      int y = 1000 - x;
      System.out.println(y);
    } else {
      System.out.println(x);
    }
  }
}