import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
} import java.io.*; io.* java public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    } main {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    } BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in)); reader new BufferedReader (new InputStreamReader (System.in)) int N = Integer.parseInt (reader.readLine().replace (" ", "")); N Integer.parseInt (reader.readLine().replace (" ", "")) Integer.parseInt Integer reader.readLine().replace (" ", "") reader.readLine().replace reader.readLine() reader.readLine reader " " "" System.out.println ((1000 - N % 1000) % 1000) System.out.println System.out System System.out (1000 - N % 1000) % 1000 (1000 - N % 1000) 1000 N % 1000 N 1000 1000 return; String[] args args public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
} public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
} Main
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
}