import java.util.Scanner;

public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
} Main public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    } abc173_a {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    } try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        } {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int change = a % 1000; change a % 1000 a 1000 if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change); change == 0 change 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(1000 - change) System.out.println System.out System System.out 1000 - change 1000 change public static void main(String[] args) {
        abc173_a();
    } main {
        abc173_a();
    } abc173_a() abc173_a String[] args args public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
} public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
} Main
import java.util.Scanner;

public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
}