//package beg_173;
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    }
} Main public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    } main {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int a = s.nextInt(); a s.nextInt() s.nextInt s int b = a%1000; b a%1000 a 1000 System.out.println((1000-b)%1000) System.out.println System.out System System.out (1000-b)%1000 (1000-b) 1000 b 1000 String[] args args public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    }
} public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    }
} Main
//package beg_173;
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = a%1000;
        System.out.println((1000-b)%1000);

    }
}
