import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()

    if (n % 1000 == 0) {
      println(0)
    } else {
      val i = n / 1000
      val ans = (i + 1) * 1000 - n

      println(ans)
    }
  }
}
