import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.*; util.* java class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
} Main void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    } solve {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0) System.out.println System.out System System.out n % 1000 != 0 ? 1000 - n % 1000 : 0 n % 1000 != 0 n % 1000 n 1000 0 1000 - n % 1000 1000 n % 1000 n 1000 0 scan.close() scan.close scan public static void main(String[] args){
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}
