N = eval(input())

M = int(N)

 

def cal(a):

	return a%1000

 

 

if M % 1000==0:

  print((0))

 

 

else:

	print((1000-cal(M)))
N=int(eval(input()))



if	N%1000==0:

	print((0))



else:

	N1=N%1000



	print((1000-N1))
N = eval(input())
M = int(N)


def cal(a):
    return a % 1000


if M % 1000 == 0:
    print((0))
else:
    print((1000 - cal(M)))

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

-N = eval(input()) -M = int(N) - - -def cal(a): -    return a % 1000 - - -if M % 1000 == 0: +N = int(eval(input())) +if N % 1000 == 0: -    print((1000 - cal(M))) +    N1 = N % 1000 +    print((1000 - N1))