N = int(eval(input()))

if N%1000 != 0:

  print((1000 - N%1000))

else:

  print((0))

# n, m, l = map(int, input().split())



# list_n = list(map(int, input().split()))



# n = input()

# list = [input() for i in range(N)



# list = [[i for i in range(N)] for _ in range(M)]



import sys

input = sys.stdin.readline



N = int(eval(input()))

if N % 1000 != 0:

    print((1000 - N % 1000))

else:

    print((0))

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

# n, m, l = map(int, input().split())
# list_n = list(map(int, input().split()))
# n = input()
# list = [input() for i in range(N)
# list = [[i for i in range(N)] for _ in range(M)]
import sys

input = sys.stdin.readline
N = int(eval(input()))
if N % 1000 != 0:
    print((1000 - N % 1000))
else:
    print((0))

+# n, m, l = map(int, input().split()) +# list_n = list(map(int, input().split())) +# n = input() +# list = [input() for i in range(N) +# list = [[i for i in range(N)] for _ in range(M)] +import sys + +input = sys.stdin.readline