n = int(eval(input()))

if n%1000:

    print((1000 - n % 1000))

else:

    print((0))
"""

atcoder : 173A

auther : Jay Saha

handel : ponder2000

date : 15/07/2020

"""



n = int(eval(input()))

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

"""
atcoder : 173A
auther : Jay Saha
handel : ponder2000
date : 15/07/2020
"""
n = int(eval(input()))
print(((1000 - n % 1000) % 1000))

+""" +atcoder : 173A +auther : Jay Saha +handel : ponder2000 +date : 15/07/2020 +""" -if n % 1000: -    print((1000 - n % 1000)) -else: -    print((0)) +print(((1000 - n % 1000) % 1000))