n=int(eval(input()))



if n%1000 == 0:

    print((0))

else:

    print((1000-n%1000))

n = int(eval(input()))



amari = n%1000



if amari == 0:

    print((0))

else:

    print((1000-amari))

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

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

-if n % 1000 == 0: +amari = n % 1000 +if amari == 0: -    print((1000 - n % 1000)) +    print((1000 - amari))