import java.util.*;

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

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