import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    }
} Main public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    } main {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter pw=new PrintWriter(System.out); pw new PrintWriter(System.out) int n=Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br pw.println(1000*(int)Math.ceil((double)n/1000)-n) pw.println pw 1000*(int)Math.ceil((double)n/1000)-n 1000*(int)Math.ceil((double)n/1000) 1000 (int)Math.ceil((double)n/1000) Math.ceil Math (double)n/1000 (double)n 1000 n pw.flush() pw.flush pw pw.close() pw.close pw String args[] args public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    }
} public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    }
} Main
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        pw.println(1000*(int)Math.ceil((double)n/1000)-n);
        pw.flush();
        pw.close();
    }
}