n = int(eval(input()))



for i in range(1, 11):

    if n <= i * 1000:

        print((i * 1000 - n))

        exit()
n = int(eval(input()))



print((0 if n % 1000 == 0 else 1000 - n % 1000))
n = int(eval(input()))
for i in range(1, 11):
    if n <= i * 1000:
        print((i * 1000 - n))
        exit()

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

-for i in range(1, 11): -    if n <= i * 1000: -        print((i * 1000 - n)) -        exit() +print((0 if n % 1000 == 0 else 1000 - n % 1000))