import java.util.Scanner;


public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    } main {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int price = sc.nextInt(); price sc.nextInt() sc.nextInt sc int a = (price+1000-1)/1000; a (price+1000-1)/1000 (price+1000-1) price+1000 price 1000 1 1000 int r = a*1000 - price; r a*1000 - price a*1000 a 1000 price System.out.println(r) System.out.println System.out System System.out r String[] args args public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    }
} public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    }
} Main
import java.util.Scanner;


public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        int a = (price+1000-1)/1000;
        int r = a*1000 - price;
        System.out.println(r);
        
//        if(price < 1000) {
//            System.out.println(price);
//        } else {
//            int surplus = price % 1000;
//            int change  = 1000 - surplus;
//            System.out.println(change);
//        }
    }
}