import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
} import java.io.IOException; IOException java.io public class Main {
    public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
} Main public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    } main {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    } StringBuilder builder = new StringBuilder(); builder new StringBuilder() int buf; buf while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        } (buf = System.in.read()) != '\n' (buf = System.in.read()) buf System.in.read() System.in.read System.in System System.in '\n' {
            builder.appendCodePoint(buf);
        } builder.appendCodePoint(buf) builder.appendCodePoint builder buf int num = Integer.parseInt(builder.toString()) % 1000; num Integer.parseInt(builder.toString()) % 1000 Integer.parseInt(builder.toString()) Integer.parseInt Integer builder.toString() builder.toString builder 1000 if (num > 0) System.out.print(1000 - num);
        else System.out.print(0); num > 0 num 0 System.out.print(1000 - num) System.out.print System.out System System.out 1000 - num 1000 num System.out.print(0) System.out.print System.out System System.out 0 String[] args args public class Main {
    public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
} public class Main {
    public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
} Main
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
}
