import scala.math.floor
import scala.io.StdIn

object Main extends App {
  var input = StdIn.readInt()

  var firstInt = 0
  if(input % 1000 == 0) {
    firstInt = floor(input / 1000).toInt
  } else {
    firstInt = floor(input / 1000).toInt + 1
  }
  
  val money = firstInt * 1000
  println(money - input);
}