import java.util.*;
  public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    }
  } import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    }
  } Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        } int i=0; int i=0; i 0 i<=N i N i++ i++ i {
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        } {
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        } int ans = 1000*i - N; ans 1000*i - N 1000*i 1000 i N if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          } ans >= 0 ans 0 {
            System.out.println(ans);
            break;
          } System.out.println(ans) System.out.println System.out System System.out ans break; if (ans < 0) {
            continue;
          } ans < 0 ans 0 {
            continue;
          } continue; 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=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    }
  } public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    }
  } Main
import java.util.*;
  public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=0; i<=N; i++){
          int ans = 1000*i - N;
          if (ans >= 0){
            System.out.println(ans);
            break;
          } else if (ans < 0) {
            continue;
          }
        }
    }
  }