import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	}
	} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	}
	} Main public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	} main {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan scan.close() scan.close scan int remainder; remainder if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	} (N % 1000) == 0 (N % 1000) N 1000 0 {
		remainder = 0;
	} remainder = 0 remainder 0 {
		remainder = 1000 - N % 1000;
	} remainder = 1000 - N % 1000 remainder 1000 - N % 1000 1000 N % 1000 N 1000 System.out.println(remainder) System.out.println System.out System System.out remainder String[] args args public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	}
	} public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	}
	} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
	scan.close();
	int remainder;
	if((N % 1000) == 0) {
		remainder = 0;
	}
	else {
		remainder = 1000 - N % 1000;
	}
	System.out.println(remainder);
	}
	}