import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    }
} import java.util.*; util.* java public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    }
} Main public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    } main {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int varN = Integer.parseInt(sc.next()); varN Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int result = 0; result 0 result = 1000 - (varN % 1000) result 1000 - (varN % 1000) 1000 (varN % 1000) varN 1000 if (result == 1000) {
            result = 0;
        } result == 1000 result 1000 {
            result = 0;
        } result = 0 result 0 System.out.println(result) System.out.println System.out System System.out result final String[] args args public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    }
} public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    }
} Main
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = 1000 - (varN % 1000);
        if (result == 1000) {
            result = 0;
        }
        System.out.println(result);
    }
}