import java.util.*;
import java.io.*;


class Main {

    public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int answer = (int)(Math.ceil(n/1000.0));
        out.println(answer*1000 - n);

        out.flush();
        out.close();

    }

    static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    }

} import java.util.*; util.* java import java.io.*; io.* java class Main {

    public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int answer = (int)(Math.ceil(n/1000.0));
        out.println(answer*1000 - n);

        out.flush();
        out.close();

    }

    static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    }

} Main public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int answer = (int)(Math.ceil(n/1000.0));
        out.println(answer*1000 - n);

        out.flush();
        out.close();

    } main {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int answer = (int)(Math.ceil(n/1000.0));
        out.println(answer*1000 - n);

        out.flush();
        out.close();

    } PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) 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 int answer = (int)(Math.ceil(n/1000.0)); answer (int)(Math.ceil(n/1000.0)) Math.ceil Math n/1000.0 n 1000.0 out.println(answer*1000 - n) out.println out answer*1000 - n answer*1000 answer 1000 n out.flush() out.flush out out.close() out.close out String[] args args static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    } pair long x1; x1 long x2; x2 public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        } pair {
            this.x1 = x1;
            this.x2 = x2;
        } this.x1 = x1 this.x1 this this.x1 x1 this.x2 = x2 this.x2 this this.x2 x2 long x1 x1 long x2 x2
import java.util.*;
import java.io.*;


class Main {

    public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int answer = (int)(Math.ceil(n/1000.0));
        out.println(answer*1000 - n);

        out.flush();
        out.close();

    }

    static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    }

}
