import scala.math

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i
  var n = sc.nextInt() % 1000
  if (n == 0){
    println(0)
    sys.exit()
  }
  println(1000 - n)
}
