n = int(eval(input()))

ans = 1000 - n%1000

if ans == 1000: ans = 0

print(ans)

r = 1000 - int(eval(input())) % 1000

print((r if r < 1000 else 0))

n = int(eval(input()))
ans = 1000 - n % 1000
if ans == 1000:
    ans = 0
print(ans)

r = 1000 - int(eval(input())) % 1000
print((r if r < 1000 else 0))

-n = int(eval(input())) -ans = 1000 - n % 1000 -if ans == 1000: -    ans = 0 -print(ans) +r = 1000 - int(eval(input())) % 1000 +print((r if r < 1000 else 0))