peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
amari = n % 1000
if amari == 0:
    print(0)
else:
    print(1000 - n % 1000)
n = int(input())
x = n//1000
if n % 1000:
  x += 1
print(1000*x - n)
#!/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(1000 - n)
n = int(input())
a = (n-1)//1000
print((a+1)*1000-n)
# -*- coding: utf-8 -*-
n = int(input())
print((1000-n%1000)%1000)
import math
n = int(input())
time = math.ceil(n / 1000)
ans = (time * 1000) - n
if ans <= 0:
    print(0)
else:
    print(ans)
N = int(input())
rem = N%1000
if rem == 0:
    print(0)
else:
    print(1000 - N%1000)
n = input()
num = int(n[-3:])
if num ==0:
  num = 1000
print(1000-num)
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000-n%1000)
N  = int(input())
ans = N%1000
if ans != 0:
    ans = abs(1000-ans)
print(ans)
n = int(input())

if (n%1000) != 0:
	print(1000-(n%1000))
else:
	print(0)
N = int(input())
count = int((N-1)/1000) + 1
print(1000*count-N)
N = int(input())
print(0 if N % 1000 == 0 else 1000 - N % 1000)
n=int(input())
if n%1000 == 0:print(0)
else:print(1000-(n%1000))
str = input()
int = int(str[-3:])

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

ans = 1000-(N%1000)

if ans != 1000:
    print(ans)
else:
    print(0)
N = int(input())
money = 0
while money < N:
  money += 1000
print(money - N)
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000-n%1000)
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)
x = int(input()) % 1000

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

count = (n // 1000)
money = count * 1000

if money < n:
  print((count+1) * 1000 -n)
else:
  print((count) * 1000 -n)
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000-n%1000)
n = int(input())%1000
if n:
    print(1000-n)
else:
    print(n)
N = int(input())
amari = N % 1000
if amari == 0:
    print(0)
else:
    print(1000 - amari)
mod = 1000
N = int(input())
if N%mod==0:
    print(0)
else:
    print(1000-N%mod)
def main():
    n = int(input())
    if  n % 1000 == 0:
        print(0)
    else:
        print(1000 - n % 1000)
    
    
if __name__ == '__main__':
    main()
N = int(input())


a = N//1000
change = ((a+1) * 1000) - N
if change%1000 == 0:
    change = 0

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

a = 10000

ans = (a - n) % 1000

print(ans)
import os

N = int(input())

modN = N % 1000
if modN != 0:
    res = 1000 - modN
else:
    res = 0

print(res)
x=int(input())
z=x%1000
if z==0:
    print(0)
else:
    print(1000-z)
N = int(input())
a = N//1000
b = ((a+1)*1000)-N
if b%1000 == 0:
	b = 0
    
print(b)
#A - Payment
N = int(input())
#おつり
out = 1000 - (N % 1000)
if out == 1000: out = 0
# 出力
print(out)
#!/usr/bin/env python3


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


if __name__ == '__main__':
    main()
def main():

    n = int(input())
    while n > 1000:
        n -= 1000
    print(1000 - n)

if __name__ == "__main__":
    main()
n=int(input())
r=n%1000
if 1000-r==1000:
  print(0)
else:
  print(1000-r)
N = int(input())
S = divmod(N, 1000)
if S[1] == 0:
  print (S[1])
else:
  print (1000 - S[1])
N = int(input())
res = 0
if N%1000 != 0:
  res = 1000-(N%1000)
print(res)
N = int(input())
k = N%1000
if k == 0:
    k=1000
print(1000-k)
n=int(input())
if n%1000!=0:
    print(1000-n%1000)
else:
    print(0)
n = int(input())
#l = list(map(int, input().split()))
if n%1000 == 0:
  print(0)
else:
  print(1000-n%1000)
N = int(input())

answer = 1000 - (N%1000)
answer = answer%1000

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

while n > 1000:
    n -= 1000
print(1000 - n)
import math

x = int(input())
y = math.ceil(x/1000)

print(1000*y-x)
def solve():
    N = int(input())
    print((1000-N%1000)%1000)

if __name__ == "__main__":
    solve()
n = int(input())
a = n // 1000
if n % 1000 != 0:
    b = a + 1
    print(f"{1000*b-n}")
else:
    print("0")
A = int(input())

result = A%1000

if result != 0:
    result = 1000 - result

print(result)
d = int(input())
a = d % 1000

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

ans = n % 1000

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

while True:
    N -= 1000
    if N <= 0:
        break

print(abs(N))
from math import log10

n = int(input())

i = 1

while True:
    if n <= 1000 * i:
        print((1000 * i) - n)
        break

    i += 1
import math
n = int(input())
num = int(math.ceil(float(n)/1000))
print(num*1000-n)
price = input()
if not int(price) % 1000:
    print("0")
else:
    if len(price) > 3:
        result = 1000 * (int(list(price)[0])+1) - int(price)
    else:
        result = 1000 - int(price)
    print(result)
N = int(input())

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

a = 1000

while N>a:
  a += 1000
  
print(a-N)
N = int(input())
k = 1000
while(N > k):
    k += 1000
print(k - N)
a = int(input())

b = a % 1000

if b == 0:
  print(0)
else:
  print(1000 - b)
N = int(input())
print((1000 - N%1000)%1000)
N = int(input())
i = 0
while True:
  if 0 < N <= 1000 * i:
    print(1000 * i - N)
    break
  i += 1
n=int(input())
print(((-(-n//1000))*1000)-n)
n = int(input())
if n%1000==0:
    ans=0
else:
    x=n%1000
    ans=1000-x
print(ans)
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print((n // 1000 + 1) * 1000 - 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(0)
else:
  print(1000 - (n % 1000))
n=int(input())
ans=0
for i in range(1000):
  ans=n+i
  if ans%1000==0:
    print(i)
    break
"""
https://atcoder.jp/contests/intro-heuristics/tasks/intro_heuristics_a
"""

import numpy as np


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N, = load_input_as_int_array()
    focus = N % 1000
    result = 1000 - focus if focus != 0 else 0
    print(result)


main()
N = int(open(0).read())
m = N % 1000
if m == 0:
    print(0)
else:
    print(1000 - m)
def main():
    N = int(input())
    r, m = divmod(N, 1000)

    if m == 0:
        print(0)
    else:
        print(1000 - m)

if __name__ == "__main__":
    main()
import sys
N=int(input())
i=0
for i in range(0,10001,1000):
    if i >= N:
        print(i-N)
        sys.exit()
n=int(input())
import math
m=math.ceil(n/1000)
print(m*1000-n)
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))
n = int(input())
if n%1000 == 0:
  print(0)
else:
  print(1000-n%1000)
N=int(input())
ans=N%1000
if ans!=0:
    ans=1000-ans
print(ans)
def resolve():
    pay = int(input()[-3:])
    rest = 1000 - pay
    if pay == 0:
        print(0)
    else:
        print(rest)

resolve()
a=input()

if len(a)==4 or len(a)==5:
  b=a[1:]
  c=1000-int(b)
  if c==1000 :
    print('0')
  else:
    print(c)
  
else:
  print(1000-int(a))
def solve(n):
    return 0 if n % 1000 == 0 else 1000 - n % 1000
    
n = int(input())
print(solve(n))
N = int(input())
if (N % 1000 == 0):
    print(0)
else:
    print(1000 - N % 1000)
import math

N = int(input())

res = int(math.ceil(N / 1000)) * 1000 - N

print(res)
N = int(input())
if N%1000!=0:
  print(str(1000-N%1000))
else:
  print(str(0))
def main():
    n = int(input())
    x = 0
    while x < n:
        x += 1000
    print(x - n)

if __name__ == "__main__":
    main()
n = int(input())
x = (n+1000-1)//1000
x*=1000
print(x-n)
n = int(input())
a = n % 1000
if a == 0:
    ans = 0
else:
    ans = 1000 - a
print(ans)
n = int(input())
if n % 1000 != 0:
    print(1000-(n%1000))
else:
    print(0)
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N = ini()
    d = N % 1000
    if d == 0:
        return 0
    return 1000 - d


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

#print(n)

while n > 0:
  n -= 1000
  
print(abs(n))
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    print(0 if n % 1000 == 0 else 1000 - n % 1000)


if __name__ == '__main__':
    main()
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
mult = (N + 999) // 1000

print(mult * 1000 - N)
N = int(input())
print((1000-N%1000)%1000)
n = int(input())

if n%1000 == 0:
    print(0)
else:
    ans1 = n//1000+1
    ans2 = ans1*1000
    print(ans2-n)
#array=map(int,input().split())
N=int(input())
turi=(N//1000)*1000-N
if turi<0: turi+=1000
print(turi)
N=int(input())
if N%1000==0:
  print(0)
else:
	print(1000-N%1000)
n = int(input())
if n% 1000 == 0:
    print(0)
else:
    print(1000 - n%1000)
N = int(input())

x = N % 1000

if(x != 0):
  print(1000-x)
else:
  print(0)
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
ans = N%1000
if(ans != 0):
  ans = 1000-ans

print(ans)
n = int(input())
while n > 1000:
    n -= 1000
print(1000 - n)
N = int(input())


while N >= 0:
  N -= 1000
  if N == 0:
    break

print(abs(N))
print( 1000 - (int(input())-1)%1000-1)
N=1000-int(input())%1000
print(N*(N<1000))
N = (int)(input())

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

for i in range(1, 11):
    if 1000 * i >= N:
        break
print(1000 * i - N)
n = input()
x = 1000-int(n[-3:])
print(0 if x == 1000 else x)
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    bill = n // 1000 + 1
    print(1000*bill - n)
N=int(input())
i=1
while 1000*i<N:
    i+=1
print(1000*i-N)
n = int(input())
if(n%1000==0):
  print(0)
else:
  print(1000 - (n%1000))
N=int(input())
n=N%1000
if n==0:
    print(n)
else:
    print(1000-n)
N = int(input())
k = (N + 999)//1000
print(k*1000 - N)
n = int(input())

print((1000 - n % 1000) % 1000)
N = int(input())
A=int(N/1000)+1

if N%1000 == 0:
  print(0)
else:
  print(abs((A*1000)-N))
n = int(input())
res = n % 1000
if (res > 0):
  res = 1000 - res
print(res)
import math
n = int(input())
print(math.ceil(n/1000)*1000 - n)
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.8.2)

import math
import statistics
import numpy as np
import queue
import itertools
import functools 

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

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

if n % 1000 == 0:
    print(0)
else:
    ans = 1000 - n % 1000
    print(ans)
N = int(input())
# N=map(int,input().split())
# A=list(map(int,input().split()))
# B=list(map(int,input().split()))

n = N // 1000 
if N % 1000 == 0:
    print((1000*n)-N)
else:
    print((1000*(n+1))-N)
n = int(input())
rem = n % 1000
if rem == 0:
    print(0)
else:
    div = (n // 1000) + 1
    print((div * 1000) - n)
N = int( input( ) )
x = N % 1000
if x == 0 :
    print( '0' )
else :
    print( 1000 - int(x) )
a = int(input())
i = 0
while 1000 * i < a:
    i += 1
print(1000 * i - a)
n = int(input())
if (n%1000 ==0):
  print(0)
else:
  print(1000 - n%1000)
N = int(input())
for i in range(100):
    if i*1000>=N:
        print(i*1000-N)
        break
N, = map(int, input().split())
if N%1000:
    print(1000-(N%1000))
else:
    print(0)
N = int(input())
maisuu = N // 1000 if N % 1000 == 0 else N // 1000 + 1
print(maisuu * 1000 - N)
n=int(input())
ans=1000
if n<100:
    print(abs(n-ans))
    exit()
else:
    ans=1000
    while(n>=ans):
        if ans==n:
            break
        elif ans>n:
            break
        else:
            ans+=1000
print(abs(n-ans))
n=int(input())
t=n % 1000
s=1000 - t
if s==1000:
    print(0)
else:
    print (s)
N = int(input())
ans = []
for i in range(1,12):
    ans.append(((i*1000)-N))
print(min([i for i in ans if i >= 0]))
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = math.ceil(n/1000)
    ans = 1000*a-n
    print(ans)
    return

if __name__=='__main__':
    Main()
N = int(input())
ans = N // 1000

if N % 1000 == 0:
  print(0)
else:
  print(1000*(ans+1) - N)
n = int(input())
if n%1000 == 0:
    print(0)
else:
    d = n//1000
    print((d+1)*1000 - n)
n = int(input())

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

n = int(input())

s = math.ceil(n/1000)
print(int(s*1000 - n))
# -*- coding: utf-8 -*-
n = int(input())
print(1000-(n%1000) if n%1000 != 0 else 0)
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())
amari = N % 1000
print(1000 - amari if amari != 0 else 0)
N = int(input())

while True:
    if N >= 1000:
        N -= 1000
    else:
        break

if N == 0:
    print(0)
else:
    print(1000-N)
n = int(input())
if n % 1000 != 0:
    print(1000 - (n % 1000))
else:
    print(n % 1000)
n=input()
# print(n[-3:])
a=1000-int(n[-3:])
if a == 1000 :
    print(0)
else:
    print(1000-int(n[-3:]))
N = int(input())

remain = N % 1000
print((1000-remain) % 1000)
N=int(input())
m=N%1000
ans=1000-m
if ans==1000:
    print(0)
else:
    print(ans)
a = int(input().rstrip())
n = [i for i in range(1,11) if(a <=i *1000)]
print((min(n)*1000) - a)
N = int(input())
if N%1000 == 0:
  print(0)
else:
  
  a = N//1000 + 1
  print(a*1000 -N)
_MULTITEST = False
##
def solve():
    n = int(input())
    k = (n // 1000) + (1 if n % 1000 != 0 else 0)
    print(k*1000 - n)

##
if __name__ == "__main__":
    t = (int(input()) if _MULTITEST else 1)
    for tt in range(t):
        solve()
n = int(input())
ans = (1000-n%1000)%1000
print(ans)
n = int(input())
res = 0
while res < n:
    res+=1000
print(res-n)
N = int(input())
if N%1000==0:
    print(0)
else:
    print(1000-N%1000)
n = int(input())
print(0 if n % 1000 == 0 else 1000 - n % 1000)
n = int(input())
if n % 1000 == 0:
  print("0")
  exit()
print(1000 - (n % 1000))
n = int(input())

answer = (-n) % 1000
print(answer)
N = int(input())
print(1000-N % 1000 if N % 1000 else 0)
n=int(input())
c=n%1000
if c==0:
  print(0)
else:
  print(1000-c)
N = int(input())

print(((N + 999)//1000)*1000 - N)
A = int(input())

for i in range(1, 11):
    tmp = 1000 * i
    if A <= tmp:
        print(tmp-A)
        break
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())



# 出力
print("{}".format((1000-(a%1000))%1000))
n=int(input())
if n%1000:
  while n>1000:
    n-=1000
  print(1000-n)
else:
  print(0)
n = int(input())

r = n % 1000
if r:
    print(1000-r)
else:
    print(0)
#!/usr/bin/env python3

N = int(input())

if N % 1000 == 0:
    print(0)
else:
    n = N // 1000
    print((n+1)*1000-N)
n = int(input())
n %= 1000
if n==0:
    print(0)
else:
    print(1000-n)
N=int(input())

x = N % 1000
print((1000 - x) % 1000)
N=int(input())

for i in range(1,10001):
    if i*1000>=N:
        ans=i*1000-N
        break
print(int(ans))
def solve():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - (N % 1000))



if __name__ == "__main__":
    solve()
def main():
    from sys import stdin

    readline = stdin.readline

    N = int(readline().rstrip())
    
    result = ( 10000 - N )%1000

    print(result)

main()
n = int(input())

a = n % 1000

if (a != 0):
    print(1000 - a)
else:
    print(0)
n = input()
n_l = int(n[-3:])
if n_l==0:
    print(0)
else:
    print(1000-n_l)
n = int(input())

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

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()

    
    ans = 1000-N%1000
    if ans==1000:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
	main()
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    
    n = (N + 999) // 1000
    ans = n * 1000 - N
    print(ans)
    
    return


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

remain = product % 1000
if remain != 0:
    change = 1000 - remain
else:
    change = 0
print(change)
import math

if __name__ == '__main__':
    n = int(input())
    num = abs(n-(math.ceil(n/1000)*1000))
    print(num)
N = int(input()) 
 
while N > 0:
  N -= 1000
 
if N < 0:
  N *= -1
 
print(N)
N = int(input())
print("{}".format(1000 - N % 1000 if N % 1000 != 0 else 0))
n = int(input())
for i in range(11):
    if n <= i * 1000:
        print(i * 1000 - n)
        exit(0)
N = int(input())
if N%1000 == 0 :
    print(0)
else :
    print(1000 - N%1000 )
n = int(input())
print((1000-n%1000)%1000)
n = int(input())

for i in range(1,11):
    tmp = i*1000
    if n==tmp:
        print(0)
        break
    else:
        if n - tmp < 0:
            print(abs(n-tmp))
            break
n = int(input())
print((1000 - n % 1000) % 1000)
x = int(input())
if x % 1000 == 0:
    print(0)
else:
    print(1000-x%1000)
n = int(input())
if n<=1000:
    print(1000-n)
else:
    mod = n%1000
    print((1000-mod) if mod>0 else 0)
s = input()
a = [int(c) for c in s]


if len(a) < 4:
    print(1000 - int(s))
elif a[-3] != 0:
    print((a[-4]+1)*1000 - int(s))
elif int(s) % 1000 != 0:
    print((a[-4]+1)*1000 - int(s))
else:
    print(0)
n=input()
m=len(n)
if m<=3:
    print(1000-int(n))
else:
    if int(n[m-3:])==0:
        print(0)
    else:
        print(1000-int(n[m-3:]))
n=int(input())
if n%1000==0:
  print(0)
else:
  print(1000-n%1000)
(N, ) = [int(n) for n in input().split()]

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


if __name__ == '__main__':
    main()
n=int(input())
while n > 0:
  n-=1000
print(n*-1)
n = int(input())
k,l = n//1000, n%1000
if l == 0:
    print(0)
else:
    print(1000 - l)
number = int(input())
if (number % 1000) == 0:
    print(0)
else:
    print(1000 - number % 1000)
n = int(input())
if(n%1000 !=0):
    print(abs(n%1000 - 1000))
    
else:print(0)
N = int(input())
if N%1000==0:
    q = N//1000-1
else:
    q = N//1000
ans = 1000*(q+1)-N
print(ans)
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000) )
n=int(input())
if n%1000==0:
    ans=0
else:
    ans=1000-n%1000
print(ans)
num = int(input())
val = num % 1000
if val == 0: print(0)
else: print(1000 - val)
n = int(input())
if n % 1000 != 0 :
    print(1000 - (n % 1000))
else :
    print(0)
N = int(input())
for i in range(0,10001,1000):
  if (i-N) > 0:
    print(i-N)
    break
  elif i == N:
    print(0)
    break
  else:
    pass
n = int(input())
if n % 1000 == 0:
    x = n / 1000
else:
    x = n // 1000 + 1
print(int(1000 * x - n))
N = int(input())
print((1000- N%1000)%1000)
n = int(input())

for i in range(1000, 10001, 1000):
    if i >= n:
        print(i-n)
        exit()
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    import math
    print(math.ceil(n/1000)*1000-n)


resolve()
N = int(input())
print(1000*((N-1)//1000 + 1) - N)
import math
cost=int(input())
payment=math.ceil(cost/1000)*1000
print(payment-cost)
N = int(input())
if N%1000==0:
  A = 0
else:
  A =1000-( N % 1000)
print(int(A))
a=int(input())
b=a%1000
if b==0:
  print(0)
else:
  print(1000-b)
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

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

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

i = 1
while 1000 * i < N:
	i += 1
	
print(1000 * i - N)
N=int(input())
x=1000-N%1000
if x==1000:
  print(0)
else:
  print(x)
def main():
    n = int(input())

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


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

for i in range(100):
    if 1000 * i >= N:
        break
print(1000 * i - N)
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


if __name__ == "__main__":
    n = int_in()
    n %= 1000
    n = n if n == 0 else 1000 - n
    out(n)
n = int(input())
res = 1000-(n%1000)
print(res%1000)
#import 
#=input()
n=int(input())
#=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]
if n%1000 != 0:
    print(1000-n%1000)
else:
    print(0)
n = int(input())
o = n + 1000 #1500
o = o // 1000 #1
o = o * 1000 #1000

if n % 1000 == 0:
    print(o - n -1000)
else:
    print(o - n)
import math
n=int(input())
print(math.ceil(n/1000)*1000-n)
n = int(input())
if n > 0:
  if n % 1000 == 0:
    print(0)
  else:
  	print(int(1000 - (n%1000)))
N = int(input())
th = N % 1000
if th != 0:
	ans = 1000 - th
	print(ans)
else:
  	print("0")
n = int(input())

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

if n%1000 == 0:
    ans = 0
else:
    ans = 1000 - n%1000
print(ans)
N = int(input())
if N%1000 == 0:
    print(0)
else:
    print(1000*(N//1000 + 1) - N)
N=int(input())
N%=1000
if N>0:
    print(1000-N)
else:
    print(0)
a = int(input())
count = 0
for i in range(1,1000000000):
  if 1000 * i - a < 0:
   count += 1
  else:
    1000 *i - a >= 0
    print(int(1000 * i - a))
    break
n = int(input())
r = n
while (True):
  if r <= 1000:
    break
  r = r - 1000
if r == 0:
  print(0)
else:
  print(1000 - r)
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    ans = 1000-N%1000
    if ans ==1000:
        print(0)
    else:
        print(ans)

if __name__ == '__main__':
    main()
N = int(input())
n = N//1000
if n*1000 == N:
  print(0)
else:
  print((n+1)*1000-N)
N=int(input())
A=((N+1000-1)//1000)*1000-N
print(A)
n = int(input())

ans = (1000 - (n % 1000)) % 1000

print(ans)