N = int(eval(input()))



r = N % 1000



if r == 0:

  print((0))

else:

  q = (N // 1000) + 1

  print((q*1000 - N))
N = int(eval(input()))



r = N % 1000



if not r:

  print((0))

else:

  q = N // 1000

  print(((q+1) * 1000 - N))
N = int(eval(input()))
r = N % 1000
if r == 0:
    print((0))
else:
    q = (N // 1000) + 1
    print((q * 1000 - N))

N = int(eval(input()))
r = N % 1000
if not r:
    print((0))
else:
    q = N // 1000
    print(((q + 1) * 1000 - N))

-if r == 0: +if not r: -    q = (N // 1000) + 1 -    print((q * 1000 - N)) +    q = N // 1000 +    print(((q + 1) * 1000 - N))