import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	}

	
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt; public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	}

	
} Main public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	} main {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	} BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); read new BufferedReader(new InputStreamReader(System.in)) PrintWriter prnt = new PrintWriter(System.out); prnt new PrintWriter(System.out) StringBuilder sb = new StringBuilder(); sb new StringBuilder() StringTokenizer st = new StringTokenizer(read.readLine()); st new StringTokenizer(read.readLine()) int n = parseInt(st.nextToken()); n parseInt(st.nextToken()) parseInt st.nextToken() st.nextToken st int a = n % 1000; a n % 1000 n 1000 if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        } a==0 a 0 {
        	System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
        	System.out.println(1000-a);
        } System.out.println(1000-a) System.out.println System.out System System.out 1000-a 1000 a String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	}

	
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	}

	
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter prnt = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(read.readLine());
        
        int n = parseInt(st.nextToken());
        
        int a = n % 1000;
        
        if(a==0) {
        	System.out.println(0);
        }
        else {
        	System.out.println(1000-a);
        }

	}

	
}
