import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val pay = if(N % 1000 > 0) (N / 1000 + 1) * 1000 else N
    
    println(pay - N)
  }
}