m = int(input())
for i in range(0, 11):
    if i * 1000 < m <= (i + 1) * 1000:
        m = (i + 1) * 1000 - m
print(m)

7919f9b6ada7688384315a2c3181b7f868ee3f2a
<mask token>

<mask token>
for i in range(0, 11):
    if i * 1000 < m <= (i + 1) * 1000:
        m = (i + 1) * 1000 - m
print(m)

m = int(input())
for i in range(0, 11):
    if i * 1000 < m <= (i + 1) * 1000:
        m = (i + 1) * 1000 - m
print(m)
