import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val n = readint()
    if(n % 1000 == 0) println(0)
    else println(1000 - n % 1000)
}



fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

