object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)

    val a = datN % 1000
    val ans = if (a == 0) a else (1000 - a)
    println(ans)
  }
}
