import java.util.*
fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    val N = reader.nextInt()
    var result = N % 1000
    if(result != 0){
        result = 1000 - result
    }
    
    println(result)
}