N = int(eval(input()))

if N%1000 == 0:

    print((0))

else:

    Str = str(N)

    if len(Str) > 3:

        K = (int(Str[0]) + 1) * 1000

        print((K - N))

    else:

        print((1000 - N))

n = int(eval(input()))

if n % 1000 == 0:

    print((0))

else:

    k = int(((n/1000)+1))*1000

    print((k-n))
N = int(eval(input()))
if N % 1000 == 0:
    print((0))
else:
    Str = str(N)
    if len(Str) > 3:
        K = (int(Str[0]) + 1) * 1000
        print((K - N))
    else:
        print((1000 - N))

n = int(eval(input()))
if n % 1000 == 0:
    print((0))
else:
    k = int(((n / 1000) + 1)) * 1000
    print((k - n))

-N = int(eval(input())) -if N % 1000 == 0: +n = int(eval(input())) +if n % 1000 == 0: -    Str = str(N) -    if len(Str) > 3: -        K = (int(Str[0]) + 1) * 1000 -        print((K - N)) -    else: -        print((1000 - N)) +    k = int(((n / 1000) + 1)) * 1000 +    print((k - n))