import java.util.*;

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

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