import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = (int)Math.ceil(n/1000.0); q (int)Math.ceil(n/1000.0) Math.ceil Math n/1000.0 n 1000.0 System.out.println(1000*q-n) System.out.println System.out System System.out 1000*q-n 1000*q 1000 q n String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	}

} Main
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = (int)Math.ceil(n/1000.0);
		System.out.println(1000*q-n);
	}

}
