import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toLong()
    var x = kotlin%1000
    if(x>0)
        println(1000-x)
    else
        println(x)
}
