def main():

    n = int(eval(input()))

    n = n % 1000

    r = 1000 - n

    if r == 1000:

        print((0))

    else:

        print(r)





if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

from math import ceil

#import numpy as np

def main():

    n = int(eval(input()))

    r = ceil(n / 1000) * 1000 - n

    print(r)



if __name__ == '__main__':

    main()

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


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from math import ceil

# import numpy as np
def main():
    n = int(eval(input()))
    r = ceil(n / 1000) * 1000 - n
    print(r)


if __name__ == "__main__":
    main()

+import sys + +read = sys.stdin.read +readline = sys.stdin.readline +readlines = sys.stdin.readlines +from math import ceil + +# import numpy as np -    n = n % 1000 -    r = 1000 - n -    if r == 1000: -        print((0)) -    else: -        print(r) +    r = ceil(n / 1000) * 1000 - n +    print(r)