import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
} 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 m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = n/1000; m n/1000 n 1000 if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        } n%1000 ==0 n%1000 n 1000 0 {
          System.out.print(0);
        } System.out.print(0) System.out.print System.out System System.out 0 {
          int p = (m+1)*1000-n;
          System.out.print(p);
        } int p = (m+1)*1000-n; p (m+1)*1000-n (m+1)*1000 (m+1) m 1 1000 n System.out.print(p) System.out.print System.out System System.out p String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
}