peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
while n >= 1000:
    n -= 1000
if n == 0:
    print(n)
else:
    print(1000 - n)
N = int(input())

if N%1000 == 0:
    print(0)
else:
    print(1000 - N%1000)
money=int(input())
i=0
while i<=money:
    if i*1000>=money:
        break
    else:
        i+=1
print(i*1000-money)
N = int(input())
while( N > 0 ):
    N -= 1000
print(-N)
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000-N % 1000)
n = int(input())
if n % 1000 != 0:
    print(1000-n%1000)
else:
    print(0)
N=int(input())
if N%1000>0:
    print(1000-N%1000)
else:
    print(0)
import math

N = int(input())

q = N / 10**3
pay = math.ceil(q) * 10**3

print(pay - N)
def resolve():
    N = int(input())
    print(((N+999)//1000)*1000-N)

resolve()
n = int(input())
n %= 1000
print((1000-n)%1000)
# coding: utf-8
# Your code here!
price=int(input())

if(price%1000==0):
    change=0
else:
    for i in range(11):
        change=1000*i-price
        if(change>0):
            break
        
print(change)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    n = int(input())
    tmp = n % 1000
    ans = 1000 - tmp
    if ans == 1000:
        ans = 0
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug
n = int(input())
result = n % 1000
print(0 if result == 0 else 1000 - result)
n = int(input())

cnt = 0
if n % 1000 > 0:
    cnt = int((n / 1000) + 1)
else:
    cnt = n / 1000
print(int(cnt*1000 - n))
import math

n = int(input())

print(math.ceil(n / 1000) * 1000 - n)
N=int(input())
if N%1000==0:
    print(0)
else:
    maisu=(N//1000)+1
    print(-N+1000*maisu)
import math

n = int(input())
thousand = math.ceil(n / 1000)
change = thousand*1000 - n
print(change)
n = int(input())

while n > 1000:
  n -= 1000

print(1000 - n)
n=int(input())%1000
print(0 if n==0 else 1000-n)
import math
N = int(input())
x = math.ceil(N/1000)
print(x*1000-N)
n = int(input())

print(0 if n % 1000 == 0 else 1000 - n % 1000)
print( (1000 - int(input()) % 1000 ) % 1000 )
n = int(input())
m = -(-n//1000)
print(1000*m-n)
import math
N = int(input())

T = math.ceil(N/1000)
print(1000*T-N)
N = int(input()) % 1000
if N == 0:
    print(0)
else:
    print(1000-N)
# coding: utf-8
# Your code here!
n = int(input())

while True:
    if n <= 1000:
        ans = 1000 - n
        break
    n -= 1000
    
print(ans)
N=int(input())

if N%1000==0:
  print(0)
else:
  print(1000 - N%1000)
n=int(input())
if n%1000==0:
  print(0)
  exit()
print((n//1000+1)*1000-n)
n = int(input())
l = [1000,2000,3000,4000,5000,6000,7000,8000,9000,10000]
for i in l:
    if n <= i:
        r = i
        break
result = r - n
print(result)
N = int(input())
if N%1000 == 0:
    print (0)
else:
    print(1000 - N%1000)
n = int(input())
if n % 1000 != 0:
    print(1000 - n % 1000)
else:
    print(0)
import math
N = int(input())
M = math.ceil(N/1000)

print(M*1000-N)
n = int(input())
ans = 0

for i in range(11):
  if i*1000 - n < 1000:
    ans = i*1000 - n
    
  elif i*1000 - n > 1000:
    i += 1
    
print(ans)
N = int(input())
if N%1000 == 0:
    print(0)
else:
    print(1000-N%1000)
N = int(input())
o = (1000-N%1000)%1000
print(o)
print(1000 - amari if (amari:=int(input())%1000) else 0)
n=int(input())%1000
if n == 0:
  print(0)
else:
  print(1000-n)
import sys

def input():
    return sys.stdin.readline()[:-1]

n = int(input())
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)
n = int(input())
keta = int(n/1000)
#print(keta)
if(n%1000==0):
    print(0)
else:
    print((keta+1)*1000-n)
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input())
    if n % 1000 == 0:
        print(0)
    else:
        print(1000 - n % 1000)


if __name__ == '__main__':
    main()
a = int(input())

if a % 1000 == 0:
    print("0")
    quit()

while a > 1000:
    a -= 1000
    if a < 1000:
        break
print(1000-a)
import sys
import math
import bisect


def main():
    n = int(input())
    ans = (1000 - n % 1000) % 1000
    print(ans)

if __name__ == "__main__":
    main()
n = int(input())
if n % 1000 == 0:
    y = 0
else:
    y = 1000 - n % 1000
print(y)
n = int(input())
k = 0--n//1000
print(k*1000-n)
n = int(input())

while True:
   
    if n <= 1000:
        print(1000-n)
        exit()
    n -= 1000
n=int(input())
for i in range(12):
    if 1000*i - n >= 0:
        print(1000*i-n)
        exit()
N = int(input())
M = (N+1000-1)//1000

ans = M*1000-N
print(ans)
# -*- coding: utf-8 -*-

a = int(input())
b = a % 1000

print(b)
n = int(input())
x = 0
for i in range(10) :
    if 1000*i>n and x == 0:
        x = i

print(1000*x-n)
import math
n=int(input())
print(1000*math.ceil(n//1000)-n)
n=int(input())
print(min(n%1000,1000-n%1000))
n = int(input())
if n%1000 == 1:
    print(0)
else:
    print(1000-n%1000)
n=int(input())
money=1000
while(1):
    if n<=money:
        break
    money+=1000
print(money%n)
n=int(input())
ans=n%1000
print(1000-ans)
n=int(input())
x=0
while x<n:
  x+=1000
print(n-x)
n=int(input())
while n>=1000:
    n-=1000
print(abs(n))
n = int(input())
while n >= 1000:
	n = n-1000
print(1000-n)
n = int(input())
t1 = n%1000
t2 = (int(n/1000) + 1)*1000 - n
if t1 < t2:
  print(t1)
else:
  print(t2)
n = int(input())
x = n % 1000
if x == 0:
    print(x)
print(1000 - x)
N=int(input())

print((1+N//1000)*1000-N)
n = input()
a = int(n[:1])+1
ans = a*1000-int(n)
if(ans == 1000):
    print(0)
elif ans>1000:
    print(1000-int(n))
else:
    print(ans)
N = int(input())

for i in range(11):
    if N < 1000:
        break
    N = N - 1000
     
print(N)
x=int(input())
if(x&1000==0):
    print(0)
else:
    print(x%1000)
N = int(input()) 
tmp = N // 1000
answer = (tmp+1)*1000 -N
print(int(answer))
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/A_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
A=N%1000
print(A)
f.close()
N = int(input())
res = N%1000

if N == 0:
  print(res)
else:
  print(1000-res)
N = int(input())
while N >= 1000:
    N = N - 1000
else:
    print(N)
a=int(input())
b=a//1000
c=b+1
d=c*1000-a
print(d)
a = int(input())
b = a % 1000
print(1000 - b)
n = int(input())
ans = n%1000
if (0<=ans and ans<=500):
    print(ans)
else:
    print(1000 - ans)
n = int(input())
if (n%1000) <=500:
  print(n%1000)
else:
  print(1000-(n%1000))
n = int(input())
ans = 1000 - n % 1000
print(ans)
price = int(input())
amari = price % 1000
print(amari)
N = int(input())
ans = ((N//1000)+1)*1000-N
print(ans)
n=int(input())
print(((n//1000)+1)*1000-n)
n = int(input())
if n%1000 <= 500:
    print(n%1000)
else:
    print(1000-n%1000)
N = int(input())
div = N % 1000
exc = (div + 1)*1000 -N
print(exc)
n = int(input())

while n >= 1000:
    n -= 1000
    n = max(n, 0)

# print((1000 - n % 1000) % 1000)

print(n)
n = int(input())

while n < 1000:
  n //= 1000

print(n)
n = int(input())
ans = 1000 - (n % 1000)
print (ans)
input1 = int(input())
while input1 > 999:
    input1 -= 1000
print(1000 - input1)
N=int(input())
for i in range(0,11000,1000):
  if N<=i:
    print(int(i-N))
N = int(input())
for i in range(20):
  if(N < 1000):
    break
  N -= 1000
print(str(1000-N))
n = int(input())
mod = n%1000
print(1000-mod)
N = int(input())
print((N // 1000 + 1) * 1000 - N)
n=int(input())
if(n%1000):
    print(n%1000)
#n,m=map(int,input().split())
a=int(input())
print(1000-(a%1000))
N = int(input())
otsuri = N % 1000
if otsuri > 0:
    orsuri = 1000 - otsuri
print(otsuri)
n=int(input())
k=0
while k <= n:
    k += 1000
print(k-n)
def abc173_a():
    N = int(input())

    #N = 1900
    print(1000-N%1000)






abc173_a()
n = int(input()) #10000以下

for i in range(11):
  if n >= 1000:
    n -= 1000
    
  if n < 1000:
    print(1000 - n)
    break
N=int(input())
if (N%1000)>=500:
  print(1000-(N%1000))
else:
  print((N%1000))
n = int(input())

if n < 1000:
    print(n)

elif n % 1000 == 0:
    print(0)

else:

    x = n // 1000

    y = (x+1)*1000

    print(y-n)
N = int(input())

for i in range (11):

    if(N<1000*(i+1)):
        pre = i+1
        break

ans = pre*1000 - N

print(ans)
n = int(input())

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

while N > 0:
  N = N - 1000

print(N)
n = int(input())

m = n % 1000

if m < 501:
    print(m)
else:
    print(1000-m)
N = int(input())

yen1000 = round(N / 1000)
change = (yen1000)*1000 - N

print(change)
N = int(input())
a = 1000 - (N % 1000)
print(a)
N=int(input())
S=N%1000
print(1000-S)
N = int(input())
while N >= 1000:
  N = N % 1000
print(1000 - N)
def main():
    N = int(input())
    print(1000 - (N % 1000))


if __name__ == "__main__":
    main()
n = int(input())
print((1000-n//1000)%1000)
from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())

def main():
	din=int(input())
	ar=[1000,2000,3000,4000,5000]
	if din not in ar:
		print(din-1800)
	else:
		print(0)
		
main()

'''
if __name__ == '__main__':
    main()
'''
a = int(input())
b = 0
while b <= a:
    b = b + 1000

print(abs(a-b))
import math

def main():
  N = int(input())
  
  print(N % 1000)
  
  
  
main()
a=int(input())

b=a%1000

c=a-b

d=c+1000

e=int(d-a)

print(e)
n = int(input())

ans = n % 1000

ans = 1000 - ans

print(ans)
n = input()
num = int(n[-3:])
print(1000-num)
def change(N):
  x = N%1000
  if x:
    return 1000 - x
  return 0
n=int(input())
rem=n%1000
print(min(rem,1000-rem))
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    n %= 1000
    res = min(n, 1000 - n)
    print(res)


if __name__ == '__main__':
    resolve()
import math

n = int(input())
x = round(n/1000)
s = 1000*x

if n > s:
    result = n - s
else:
    result = s - n
    
print(math.floor(result))
num = input()
num1 = int(num)
num2 = list(num)
sen = (int(num2[0])+1)*1000
n = sen-num1
print(n)
n=int(input())
r=n%1000
print(1000-r)
N = int(input())
a = ((N//1000)+1)*1000 - N
print(a)
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    satu=(n/1000)+1
    harau=satu*1000
    print(harau-n)
n = int(input()) #10000以下

for i in range(11):
  if n >= 1000:
    n -= 1000
  else:
    print(n)
    break
i = int(input().strip())
print((i // 1000 + 1) * 1000 - i)
n = int(input())
ans = 0
for i in range(10):
  if n == 1:
    ans = 999
    break
  if 1000*i >= n:
    ans = 1000*i - n
    break
print(ans)
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  cnt = (N // 1000) + 1
  ans = 1000 * cnt - N
  print(N)
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/A_input.txt")
else:
    f=sys.stdin
N=int(f.readline())
print(N%1000)
f.close()
N = int(input())
otsuri = N % 1000
print(otsuri)
from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())

def main():
	n=int(input())
	if n <= 2000:
	    print('100')
	else:
		print('0')
		
	
main()

'''
if __name__ == '__main__':
    main()
'''
def main():
    N = int(input())
    print(N%1000)

if __name__ == "__main__":
    main()
S=int(input())
if S%1000==0:
    print(0)
elif S<1000:
    print(1000-S%1000)
else:
    print((S//1000)*1000-S%1000)
n = int(input())
if n%1000 == 0:
  print(0)
else:
  if n%1000 <= 500:
    print(n%1000)
  else:
    print(1000-n%1000)
N = int(input())
N = N % 1000
print(1000-N)
N = int(input())
mod = N % 1000
if mod > 500:
    mod = 1000 - mod
print(mod)
n = int(input())
if n >= 1000:
    num = n % 1000
else:
    num = 1000 - n
print(abs(num))
N = input()
m = len(N)
if m > 3:
    N = N[-3:]

print(1000 - int(N))
n = int(input())

x = round(n / 1000)
ans = (x * 1000) - n

print(ans)
n = int(input())

a = 1000

for i in range(n//1000 + 1):
  if  n <= a*i :
    c = a*i - n
    print(c)  
    break
n = int(input())
if n < 100:
    print(1000-n)
else:
    print(1000-(n%1000))
# -*- coding: utf-8 -*-
n = int(input())
print(1000-(n%1000))
a=int(input())

if a%1000==0:
    print(a)
else:
    b=a%1000
    c=a-b
    d=c+1000
    e=int(d-a)
    print(e)
import sys
N = int(input())

num = 0
if N % 1000 == 0:
    num = N % 1000
else:
    num = (N // 1000) + 1

Money = 1000*num

change = Money % N
print(change)
# ABC173a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n = int(input())
    import math
    print(math.ceil(n/1000))


if __name__ == '__main__':
    main()
n = int(input())
x = round(n/1000)
s = 1000*x

if n > s:
    result = n - s
else:
    result = s - n
    
print(result)
N=int(input())
an=N//1000
ans=(an+1)*1000-N
if an==0:
  print(0)
else:
  print(ans)
N=int(input())
a=0
if N<1000:
    print(1000-N)
    exit()
else:
    while 1:
        if a*1000-N>0:
            print(a*1000-N)
            exit()
        else:
            a+=1
n = int(input())
a = 0
if n % 1000 == 0:
    print(0)
else:
    a = 1000 - n % 1000
print(a)
n = int(input())
n %= 1000
print(1000 - n)
N = int(input())
d = int(N % 1000)
print(1000 - d)
n = int(input())
print(n)
if n % 1000 == 0:
    ans = 0
else:
    ans = 1000 - n % 1000

print(ans)
N = int(input())
otsuri = 1000-N%1000
atai = 0
if otsuri == 0:
  print(atai)
  
else:
  print(otsuri)
N = int(input())
while True:
    N -= 1000
    if N < 1000:
        break
print(1000 - N if N != 0 else 0)
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  print(N//1000 +1 )
n = int(input())
print(1000 - (n % 1000) if 1000 - (n % 1000) is not 1000 else 0)
n = int(input())
ans = 1000 - n%1000
print(ans)
import math
n=int(input())
x=10000000
for i in range(101):
  x=min(abs(n-i*1000),x)
print(x)
import sys
import numpy as np  # noqa

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N = int(readline())
print((N-1000) % 1000)
N = int(input())
print(int(N / 1000 + 1) * 1000 - N )
a = int(input())
print(0) if a%1000==0 else print(1000-(a//1000))
import sys
n = int((input()))
if n%1000 == 0:
    print(0)
else:
    while n > 1000:
        n -= 1000
        print(1000-n)
N=int(input())
if N!=10000:
  n=N//(1000)
  ch=(n+1)*(1000)-N
  print(ch)
else:
  print(0)
N = int(input())
while N >= 1000:
    N = N - 1000
print(N)
n = int(input())
k = n//1000 + 1
ans = 1000*k - n
print(ans)
n = int(input())
a = n//1000
print(1000*(a+1) - n)
N = int(input())
for i in range(10):
  if i*1000>=N:
    print(i*1000-N)
    exit()
N = int(input())
ans = 1000 - (N % 1000)

print(ans)
N = int(input())
d = N % 1000
print(1000 - d)
def main():
    arg = int(input())
    if arg < 1000:
        ans = 1000 - arg
    else:
        ans = 1000 - (arg % 1000)
    print(str(ans))


if __name__ == '__main__':
    main()
N = int(input()) 
print(N - (N // 1000) * 1000)
a = int(input())
if a > 10000000:
    print(f"{a-10000000}")
else:
    print(f"{a % 1000}")
#! /usr/bin/python3

N = int(input())
1 <= N <= 10000

if N % 1000 == 0:
 print(0)
else:
  sen = N//1000
  sen2 = sen*1000
  atai = N-sen2
  print(atai)
N = int(input())
if (N % 1000 > 500):
	print(1000 - (N % 1000))
else:
	print(N % 1000)
n=int(input())
for i in range(10):
  if (i*1000)/n >= 1:
    break
    
print(i*1000-n)
N = int(input())

for i in range(10):
    if 1000 * i >= N:
        break
print(1000 * i - N)
n=int(input())
if(n<1000):
    print(1000-n)
else:
    a=n//1000
    print(n-(a*1000))
amount = int(input())

x = 1000

while True:
    if x < amount:
        x += x
    else:
        break
print(x - amount)
n=int(input())
if n%1000 == 0 : print(0)
else :
    ans=1000*((n/1000)+1)-n
    print(ans)
n = int(input())
a = n%1000
a = 1000-a
a%=a
print(a)
N = int(input())
print((1000 - N % 1000) % 10000)
import math
a = input()
b = int(a)
c = 1000
if len(a) < 4:
  print(c-b)
else:
  if a[-4] != '0':
    b = int(a[-3:])
    print(c-b)
  elif a[-3] != '0':
    b = int(a[-2:])
    print(c-b)
  elif a[-2] != '0':
    b = int(a[-1:])
    print(c-b)
  else:
    print(int(0))
def payment(N, paper):
  back = 1000*paper - N
  return back
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  div = N / 1000
  exc = (div +1)*1000 - N
  print(exc)
def main():
    n = int(input())
    if n < 1000:
        print(n)
    else: 
        print(str(n)[1:])



if __name__ == "__main__":
    main()
n = int(input())

while n >= 1000:
    n -= 1000

print(n)
N=(input())
a=N[0]
if int(N)<=1000:
  print(1000-int(N))

else:
  print(1000-int(N)%1000)
n = int(input())
a = n // 1000
b = a + 1
print(f"{1000*b-n}")
N = int(input())
ans = 1000 - N % 1000
print(ans)
N = int(input())

a = N//1000
change = ((a+1) * 1000) - N

print(change)
n=int(input())
a=n%1000
print(1000-a)
N= input()
x=int(N)
if x<1000:
    print(1000-x)
if x > 999:   
    while True: #0 1 2 4 5が出力される
	    x -= 1000
	    if x < 1000:
		    break   
    print(1000-x)
n = int(input())
rem = n % 1000
print(1000 - rem)
number = int(input())
thausand_number = int(number / 1000)
if number % 1000 == 0:
  print(0)
else:
  print(number - thausand_number * 1000)
in_value = int(input())

while(1):
    in_value %= 1000
    if in_value < 1000:
        in_value = 1000 - in_value
        print(in_value)
        break
n = int(input())
ans = 1000-(n%1000)
print(ans)
def change(x):
  res = x%1000
  if res:
    return 1000 - res
  return 0
from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())

def main():
	n=int(input())
	yen=1000
	if n != yen+2000:
		print(n-1800)
	else:
		print(0)
main()

'''
if __name__ == '__main__':
    main()
'''
n=int(input())
if n%1000==0:
  print(0)
else:
  print(n//1000+1)
N=int(input())
a=N%1000
if N>1000 and a>500:
      print(1000-a)
elif N>1000 and a<500:
    print(a)
elif N<1000:
    print(1000-a)
cash = int(input())

paid = 1000 - cash % 1000
print(paid)
n=int(input())
k=n//1000
print((k+1)*1000-n)
N = int(input())
s = N // 1000
print(abs(N - (s + 1) * 1000))
N = int(input())

x = N // 1000
x = 2 * x
print(x - N)
import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()

_, c = divmod(N, 1000)
print(1000 - c)
N = int( input( ) )
x = N % 1000
print( 1000 - int(x) )
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()

print(n%1000)
N=int(input())
for i in range(10):
    if i*1000>=N:print((i*1000)-N);break
# input
N = int(input())

# check
print(N % 1000)
from sys import stdin
N = int(stdin.readline().rstrip())
ans = 1000 - N % 1000
print(ans)
#!/usr/bin/env python3
import os
from sys import stdin, stdout


def solve(tc):
    n = int(stdin.readline().strip())
    print(1000 - (n%1000))


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1
N= int(input())
for i in range(0,10):
    if i*1000 >= N:
        print(i*1000 -N)
        break
n = input()
keta = len(n)
ans = int(n[keta - 3:keta]) % 1000
print(ans)
N = int(input())
# N = 1900

print(N % 1000)
def main():
    N = int(input())
    print(1000 - N % 1000)

if __name__ == '__main__':
    main()
N = int(input())
otsuri = 1000 - int(N%1000)
print(otsuri)
def main():
    n = int(input())
    print(min(n%1000,(1000-n%1000)%1000))
    

main()
n = int(input())
n1 = n%1000

if n1 == 0:
    print(0)
else:
    print(1000-n)
N = int(input())

if N > 1000:
    hasu = N - (N // 1000)*1000
else:
    hasu = N
    
print(1000-hasu)
N = int(input())
if (N % 1000 == 0):
    print("0")
else:
    print(N % 1000)
N= int(input())
for n in range(10):
    a = 1000*n -N
    if 0< a < 1000:
        print(a)
        break
print('N')
x=int(input())
x=1000-x%1000
if(x==1000):
    x=0
print(x)
import math
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    ans = n
    while True:
        ans = ans - 1000
        if(ans < 1000):
            print(ans)
            break

if __name__ == "__main__":
    main()
N = int(input())

m = N % 1000
if m == 0:
  print(0)
else:
  print(N - m)
#A - Payment
N = int(input())
a = N % 1000
if N <1000 :
    ans = 1000- a
elif a >=500:
    ans = 1000 - a
else:
    ans = a

print(ans)
N = int(input())

a = 1000

while N>=a:
  a += 1000
  
print(a-N)
num = int(input()) #ここで標準入力

while True:
    ans = num - 1000
    if ans < 1000:
        break

print(ans)
N=int(input())
m=int(N/1000)+1
change=1000*m-N
print(change)
N = int(input())
count = 0
money = 1000
while N >= money * count:
    count += 1
print(money * count - N)
N = int(input())
yen = N // 100 +1
shoki = yen * 1000
oturi = shoki - N
if oturi == 1000:
  print(int(oturi - 1000))
else:
  print(int(oturi))
N = int(input())
res =N
while res>= 1000 :
  res = res -1000
print(res)
import sys, math,os
from io import BytesIO, IOBase
#data = BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from bisect import bisect_left as bl, bisect_right as br, insort
# from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
# from decimal import Decimal
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
#sys.setrecursionlimit(100000 + 1)
INF = 10**9
mod = 998244353

N=int(data())
out(1000-N%1000)
n=int(input())
if n>1000:
  print(n%1000)
else:
  print(1000-n)
money1 = int(input())
money2 = 1000 - (money1 % 1000)
print(money2)
N = int(input())

while True:
    if N <= 1000:
        break
    N -= 1000
    
print(N)
n = int(input())
ans = n//1000

print((ans+1)*1000 - n)
n = int(input())
if (0 <= n and n <= 10000):
    if (n % 1000) == 0:
        print(0)
    else:
        n1 = n / 1000
        n2 = (n1+1) * 1000
        change = n2 - n
        print(change)
#!/usr/bin/python
# -*- Coding: utf-8 -*-

n = int(input())

if n % 1000 == 0:
    print(0)
elif n > 1000:
    a = (n//1000 + 1)*1000
    print(a - n)
else:
    print(n)
X=int(input())
while X>=1000:
  X-=1000
print(X)
N = int(input())

i = N // 1000
ans = N - i * 1000
print(ans)
a = int(input())
b = a // 1000 + 1
print(b + 1000 - a)
N=int(input())
if N%1000!=0:
    print(1000-N%1000)
else:
    print(1000-N)
n = int(input())
m = (int(n / 1000) + 1) * 1000 - n
print(m)
N = int(input())

q, mod = divmod(N, 1000)

print(1000-mod)
N = int(input())
a = 1000*(int(str(N)[0]) + 1) - N
print(a if a != 1000 else 0)
n = int(input())
amari = (n%1000)

print (1000 - amari)
n=int(input())
t=n//1000
print((t+1)*1000-n)
n = int(input())
if n<=1000:
  print(1000-n)
else:
  a = int(round(n/1000,0))
  b = 1000*a
  print(n-b)
N = int(input())
ans = []
for i in range(1,11):
    ans.append(abs((i*1000)-N))
print(min(ans))
import sys
N = int(input())

ans = 0
if N % 1000 == 0:
  ans = 0
else:
  ans = N % 1000
  
print(ans)
a = int(input())
if a <= 1000:
    b = a//1000
else:
    b = a//1000 + 1
print(b*1000 - a)
N = int(input())

n = N/1000

for i in range(10):
    if i >= n:
        print(i*1000-N)
        break
t=int(input())
m=0
while 1000*m<t:
    m=m+1
c=1000*m-t
print(t)
N = int(input("N:"))
sa = 10000 - N
ans = sa % 1000
print(ans)
#AtCoder
N = int(input())
if (N % 1000 == 0):
    print(0)
else:
    print(N % 1000)
inp = input()

value = int(inp)

amari = value % 1000

result = 1000 - amari

print(result)
N=int(input())
N%=1000
if N==0:
    print(0)
else:
    print(N)
N =int(input())
L = N % 1000
if 0<= L<=500:
    print(L)
elif 500< L < 1000:
    P = N // 1000
    K = 1000 - L
    print(K)
n = int(input())

if n < 1000:
    print(n)
else:
    for i in range(1,n):
        if 1000*i >= n:
            print(1000*i - n)
            break
N = int(input())
t = N//1000
print((t+1)*1000-N)
n = int(input())
res = 1000 - n // 1000
print(res)
x=int(input())
if x//1000==0:
  print(0)
else:
  print(1000-(x%1000))
# 整数の入力
a = int(input())
# スペース区切りの整数の入力
amari = a % 1000
# 出力
print("{}".format(amari))