import java.util.*;
public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    }

    public static void main(String[] args) {
        new Main().solve();
    }
} import java.util.*; util.* java public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    }

    public static void main(String[] args) {
        new Main().solve();
    }
} Main public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    } solve {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int A = N%1000; A N%1000 N 1000 if(A  == 0)System.out.println(0);
        else System.out.println(1000-A); A  == 0 A 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(1000-A) System.out.println System.out System System.out 1000-A 1000 A public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    }

    public static void main(String[] args) {
        new Main().solve();
    }
} public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    }

    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.*;
public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A = N%1000;
        if(A  == 0)System.out.println(0);
        else System.out.println(1000-A);

    }

    public static void main(String[] args) {
        new Main().solve();
    }
}