N = int(eval(input()))

k = N//1000

a = N%1000

if a>0:

    ans = 1000-a

else:

    ans = 0

print(ans)
import math

N = int(eval(input()))

n = math.ceil(N/1000)

print((1000*n-N))
N = int(eval(input()))
k = N // 1000
a = N % 1000
if a > 0:
    ans = 1000 - a
else:
    ans = 0
print(ans)

import math

N = int(eval(input()))
n = math.ceil(N / 1000)
print((1000 * n - N))

+import math + -k = N // 1000 -a = N % 1000 -if a > 0: -    ans = 1000 - a -else: -    ans = 0 -print(ans) +n = math.ceil(N / 1000) +print((1000 * n - N))