import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

class Main {
    public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.math.BigInteger; BigInteger java.math import java.nio.Buffer; Buffer java.nio import java.util.*; util.* java class Main {
    public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    }
} Main public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    } main {
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    } try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        } Exception e {
            System.out.println("kkkk "+ e.getMessage());
        } System.out.println("kkkk "+ e.getMessage()) System.out.println System.out System System.out "kkkk "+ e.getMessage() "kkkk " e.getMessage() e.getMessage e {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } PrintWriter out=new PrintWriter(System.out,true); out new PrintWriter(System.out,true) BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int t=Integer.parseInt(br.readLine()); t Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br t=t%1000 t t%1000 t 1000 t=1000-t t 1000-t 1000 t if(t==1000){
                t=0;
            } t==1000 t 1000 {
                t=0;
            } t=0 t 0 out.println(t) out.println out t out.close() out.close out String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

class Main {
    public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            t=t%1000;
            t=1000-t;
            if(t==1000){
                t=0;
            }
            out.println(t);
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    }
}