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

class Main
{
    public static void main(String[] args) throws IOException{
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        
        System.out.println((int)(Math.ceil(t/1000.0)*1000-t));


    }

    


    

} import java.util.*; util.* java import java.io.*; io.* java class Main
{
    public static void main(String[] args) throws IOException{
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        
        System.out.println((int)(Math.ceil(t/1000.0)*1000-t));


    }

    


    

} Main public static void main(String[] args) throws IOException{
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        
        System.out.println((int)(Math.ceil(t/1000.0)*1000-t));


    } main {
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        
        System.out.println((int)(Math.ceil(t/1000.0)*1000-t));


    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int t = Integer.parseInt(st.nextToken()); t Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st System.out.println((int)(Math.ceil(t/1000.0)*1000-t)) System.out.println System.out System System.out (int)(Math.ceil(t/1000.0)*1000-t) Math.ceil(t/1000.0)*1000 Math.ceil(t/1000.0) Math.ceil Math t/1000.0 t 1000.0 1000 t String[] args args
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args) throws IOException{
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        
        System.out.println((int)(Math.ceil(t/1000.0)*1000-t));


    }

    


    

}