from math import ceil



N = int(eval(input()))

print((ceil(N/1000)*1000 - N))
N = int(eval(input()))

print(((10000-N)%1000))
from math import ceil

N = int(eval(input()))
print((ceil(N / 1000) * 1000 - N))

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

-from math import ceil - -print((ceil(N / 1000) * 1000 - N)) +print(((10000 - N) % 1000))