import sys

def Ii():return int(sys.stdin.readline())

def Mi():return list(map(int,sys.stdin.buffer.readline().split()))

def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()

a = n%1000

if a == 0:

  print((0))

else:

  print((1000-a))
import sys

def Ii():return int(sys.stdin.readline())

def Mi():return list(map(int,sys.stdin.buffer.readline().split()))

def Li():return list(map(int,sys.stdin.buffer.readline().split()))



n = Ii()

if n%1000 == 0:

  print((0))

else:

  print((1000-n%1000))
import sys


def Ii():
    return int(sys.stdin.readline())


def Mi():
    return list(map(int, sys.stdin.buffer.readline().split()))


def Li():
    return list(map(int, sys.stdin.buffer.readline().split()))


n = Ii()
a = n % 1000
if a == 0:
    print((0))
else:
    print((1000 - a))

import sys


def Ii():
    return int(sys.stdin.readline())


def Mi():
    return list(map(int, sys.stdin.buffer.readline().split()))


def Li():
    return list(map(int, sys.stdin.buffer.readline().split()))


n = Ii()
if n % 1000 == 0:
    print((0))
else:
    print((1000 - n % 1000))

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