func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let n = Int(readLine()!)!
    if n % 1000 == 0 {
        print(0)
    } else {
        print((n / 1000 + 1) * 1000 - n)
    }
}

main()
