n=int(eval(input()))

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

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

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

-print((1000 - n % 1000 if n % 1000 != 0 else 0)) +print((0 if n % 1000 == 0 else 1000 - n % 1000))