N = int(eval(input()))

print(((1000-N%1000)%1000))
N = int(eval(input()))

tmp = N%1000

if tmp == 0:

    print((0))

else:

    print((1000 - tmp))
N = int(eval(input()))
print(((1000 - N % 1000) % 1000))

N = int(eval(input()))
tmp = N % 1000
if tmp == 0:
    print((0))
else:
    print((1000 - tmp))

-print(((1000 - N % 1000) % 1000)) +tmp = N % 1000 +if tmp == 0: +    print((0)) +else: +    print((1000 - tmp))