class Main{
	
public static void main (String[] args) {
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int N = sc.nextInt();
	boolean flag = true;
	
	while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	}
	
	System.out.println(N);
	
	sc.close();;
	
}
	
	
}
 class Main{
	
public static void main (String[] args) {
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int N = sc.nextInt();
	boolean flag = true;
	
	while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	}
	
	System.out.println(N);
	
	sc.close();;
	
}
	
	
} Main public static void main (String[] args) {
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int N = sc.nextInt();
	boolean flag = true;
	
	while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	}
	
	System.out.println(N);
	
	sc.close();;
	
} main {
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int N = sc.nextInt();
	boolean flag = true;
	
	while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	}
	
	System.out.println(N);
	
	sc.close();;
	
} java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc boolean flag = true; flag true while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	} flag {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	} N-=1000 N 1000 if (N<=0) {
			flag=false;
			N*=-1;
		} N<=0 N 0 {
			flag=false;
			N*=-1;
		} flag=false flag false N*=-1 N -1 1 System.out.println(N) System.out.println System.out System System.out N sc.close() sc.close sc String[] args args
class Main{
	
public static void main (String[] args) {
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int N = sc.nextInt();
	boolean flag = true;
	
	while (flag) {
		N-=1000;
		if (N<=0) {
			flag=false;
			N*=-1;
		}
	}
	
	System.out.println(N);
	
	sc.close();;
	
}
	
	
}

