import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  }
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  }
} Main public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  } main {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int senen = 1000; senen 1000 while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    } true {
	      if (N <= 0) { break; }
	      N = N - senen;
	    } if (N <= 0) { break; } N <= 0 N 0 { break; } break; N = N - senen N N - senen N senen System.out.println(Math.abs(N)) System.out.println System.out System System.out Math.abs(N) Math.abs Math N String[] args args
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  }
}