import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int ans = a % 1000; ans a % 1000 a 1000 if (ans != 0) {
        	ans = 1000 - ans;
        } ans != 0 ans 0 {
        	ans = 1000 - ans;
        } ans = 1000 - ans ans 1000 - ans 1000 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 sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
}