fun main() {
    val i = readLine()!!.toInt()
    if(i > 1000){
        val j = 1000 - (i%1000)
        if(j == 1000){
            println("0")
        }else{
	        println("$j")            
        }
    }else{
        val k = 1000 - i
        println("$k")
    }
}