N = int(eval(input()))

B = N//1000

if N <= 1000:

    print((1000-N))

elif N%1000 == 0:

    print((0))    

elif N > 1000:

    print((((B+1)*1000)-N))
N = int(eval(input()))

if 1000 > N:

    print((1000 - N))

elif (N//1000)*1000 == N:

    print((0))      

elif N > 1000:

    print(((((N//1000)+1)*1000)-N))
N = int(eval(input()))
B = N // 1000
if N <= 1000:
    print((1000 - N))
elif N % 1000 == 0:
    print((0))
elif N > 1000:
    print((((B + 1) * 1000) - N))

N = int(eval(input()))
if 1000 > N:
    print((1000 - N))
elif (N // 1000) * 1000 == N:
    print((0))
elif N > 1000:
    print(((((N // 1000) + 1) * 1000) - N))

-B = N // 1000 -if N <= 1000: +if 1000 > N: -elif N % 1000 == 0: +elif (N // 1000) * 1000 == N: -    print((((B + 1) * 1000) - N)) +    print(((((N // 1000) + 1) * 1000) - N))