import java.util.*;

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

public class Main {
	public static void main(String[] args){
	Scanner scn = new Scanner(System.in);
      int p = scn.nextInt();
      int a = p%1000;
      int ans = 1000-a;
      if(a==0){
        System.out.println("0");
      }else{
      	System.out.println(ans);
      }
	}
}
