import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    }

    public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    }

    public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc System.out.println(calc(n)) System.out.println System.out System System.out calc(n) calc n sc.close() sc.close sc String[] args args public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    } calc {
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    } if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        } n % 1000 == 0 n % 1000 n 1000 0 {
            return 0;
        } return 0; 0 {
            return 1000 - n % 1000;
        } return 1000 - n % 1000; 1000 - n % 1000 1000 n % 1000 n 1000 int n n public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    }

    public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    }

    public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(calc(n));
        sc.close();
    }

    public static int calc(int n){
        if(n % 1000 == 0){
            return 0;
        }else{
            return 1000 - n % 1000;
        }
    }
}