import Foundation

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

func main(){
    let value = Int(readLine()!)!
    if value % 1000 == 0 {
        print(0)
        return
    }
    print(abs(value % 1000 - 1000))
}

main()
