import sys

n = int((eval(input())))

if n%1000 == 0:

    print((0))

else:

    while n > 1000:

        n -= 1000

    print((1000-n))
import sys

n = int((eval(input())))

if n%1000 == 0:

    print((0))

else:

    for i in range(10):

        if n < 1000:

            print((1000-n))

            sys.exit()

        else:

            n -= 1000

import sys

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

import sys

n = int((eval(input())))
if n % 1000 == 0:
    print((0))
else:
    for i in range(10):
        if n < 1000:
            print((1000 - n))
            sys.exit()
        else:
            n -= 1000

-    while n > 1000: -        n -= 1000 -    print((1000 - n)) +    for i in range(10): +        if n < 1000: +            print((1000 - n)) +            sys.exit() +        else: +            n -= 1000