import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    private static void solve(int n) {
        // solve here
        System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
    private static void solve(int n) {
        // solve here
        System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    }
} Main private static void solve(int n) {
        // solve here
        System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0);
    } solve {
        // solve here
        System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0);
    } System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0) System.out.println System.out System System.out n%1000 != 0 ? 1000 - (n%1000) : 0 n%1000 != 0 n%1000 n 1000 0 1000 - (n%1000) 1000 (n%1000) n 1000 0 int n n public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br solve(n) solve n String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    private static void solve(int n) {
        // solve here
        System.out.println(n%1000 != 0 ? 1000 - (n%1000) : 0);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    }
}