cash = int(eval(input()))

 

n = 0

paid = 0

while paid < cash:

  paid = 1000 * n 

  n += 1

 

print((paid - cash))
cash = int(eval(input()))



paid = (1000 - cash % 1000) % 1000

print(paid)
cash = int(eval(input()))
n = 0
paid = 0
while paid < cash:
    paid = 1000 * n
    n += 1
print((paid - cash))

cash = int(eval(input()))
paid = (1000 - cash % 1000) % 1000
print(paid)

-n = 0 -paid = 0 -while paid < cash: -    paid = 1000 * n -    n += 1 -print((paid - cash)) +paid = (1000 - cash % 1000) % 1000 +print(paid)