import sys



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N = int(read())

x = N + (-N) % 1000

print((x - N))
import math

N = int(eval(input()))

x = math.ceil(N/1000) * 1000

print((x-N))
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(read())
x = N + (-N) % 1000
print((x - N))

import math

N = int(eval(input()))
x = math.ceil(N / 1000) * 1000
print((x - N))

-import sys +import math -read = sys.stdin.buffer.read -readline = sys.stdin.buffer.readline -readlines = sys.stdin.buffer.readlines -N = int(read()) -x = N + (-N) % 1000 +N = int(eval(input())) +x = math.ceil(N / 1000) * 1000