# -*- coding: utf-8 -*-

n = int(eval(input()))

a = 1000-n%1000

if a != 1000:

    print(a)

else:

    print((0))
# -*- coding: utf-8 -*-

n = int(eval(input()))

p = n%1000

if p != 0:

    print((1000-p))

else:

    print((0))
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = 1000 - n % 1000
if a != 1000:
    print(a)
else:
    print((0))

# -*- coding: utf-8 -*-
n = int(eval(input()))
p = n % 1000
if p != 0:
    print((1000 - p))
else:
    print((0))

-a = 1000 - n % 1000 -if a != 1000: -    print(a) +p = n % 1000 +if p != 0: +    print((1000 - p))