n = int(eval(input()))

i=1

ans=0

for i in range(100):

	if i*1000>=n:

		ans = i*1000-n

		break

print(ans)

n=int(eval(input()))

if n%1000==0:

  print((0))

else:print((1000-n%1000))
n = int(eval(input()))
i = 1
ans = 0
for i in range(100):
    if i * 1000 >= n:
        ans = i * 1000 - n
        break
print(ans)

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

-i = 1 -ans = 0 -for i in range(100): -    if i * 1000 >= n: -        ans = i * 1000 - n -        break -print(ans) +if n % 1000 == 0: +    print((0)) +else: +    print((1000 - n % 1000))