func readInt() -> Int {
    return Int(readLine()!)!
}

func main() {
    let price = readInt()
    let payment = price % 1000 == 0 ? price : (price / 1000 + 1) * 1000
    let exchange = payment - price
    print(exchange)
    return
}

main()
