import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    } main {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int ret = n % 1000; ret n % 1000 n 1000 if(ret > 0) {
            ret = 1000 - ret;
        } ret > 0 ret 0 {
            ret = 1000 - ret;
        } ret = 1000 - ret ret 1000 - ret 1000 ret System.out.println(String.valueOf(ret)) System.out.println System.out System System.out String.valueOf(ret) String.valueOf String ret String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int ret = n % 1000;
        if(ret > 0) {
            ret = 1000 - ret;
        }

        System.out.println(String.valueOf(ret));
    }
}