object Main extends App {
  //  val file = new File("targetfile")
  val testdata =
    """
1200"""
// 出力例1
// 3
//   val sc = new java.util.Scanner(testdata)
 val sc = new java.util.Scanner(System.in)

  val _x = sc.nextInt

  if (_x % 1000 > 0) {
    println(1000 - _x % 1000)
  } else {
    println(0)
  }
}
