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 out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.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 out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    }
} Main public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    } main {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); out new PrintWriter(new OutputStreamWriter(System.out)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        } n % 1000 != 0 n % 1000 n 1000 0 {
            out.println(1000 - (n % 1000));
        } out.println(1000 - (n % 1000)) out.println out 1000 - (n % 1000) 1000 (n % 1000) n 1000 {
            out.println(0);
        } out.println(0) out.println out 0 out.close() out.close out String[] args args public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.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 out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    }
}