N = int(eval(input()))

if N % 1000 == 0:

  print((0))

else:

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

if n % 1000 == 0:

  print((0))

else:

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

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

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