using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = CinT();
            Cout((1000 - n % 1000) % 1000);

            Cin();
        } //main


        static readonly int MOD10_9_7 = (1000000000 + 7);
        static Random Rand = new Random();
        static readonly string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        static int GetDigits(long num) { return (int)Floor(Log10(num)) + 1; }
        static int GetNumByDigit(long num, int digit)
        {
            return (int)((num / ((int)Pow(10, digit - 1))) % 10);
        }
        static int Loop(int num, int max)
        {
            if (num > max) { return num % max - 1; }
            else if (num < 0) { return max - (-num) % max + 1; }
            else { return num; }
        }
        static long PW10(int n) { return (long)Pow(10, n); }
        static long GCD(long a, long b)
        {
            if (a < b) { return GCD(b, a); }
            if (a % b == 0) { return b; }
            else { return GCD(b, a % b); }
        }
        static long LCM(long a, long b) { return a * b / GCD(a, b); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static void SwapArE<T>(T[] a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; }
        static void SwapLiE<T>(List<T> a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; }
        static bool IsInt(double d) { return (int)d == d; }
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { var q = Cin().Split(' '); return (q[0] == "") ? new string[0] : q; }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void Cout(object s) { WriteLine(s); }
        static string RevStr(string s) { return new string(s.Reverse().ToArray()); }
        static long[] Divisor(long n)
        {
            if (n == 1) { return new long[] { 1 }; }
            List<long> res = new List<long>() { 1, n };
            for (long i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                    long f = n / i;
                    if (f != i) { res.Add(f); }
                }
            }
            return res.ToArray();
        }
        static IEnumerable<decimal> PrimeFactors(decimal n)
        {
            decimal i = 2, tmp = n;
            while (i * i <= n)
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else { i++; }
            }
            if (tmp != 1) { yield return tmp; }
        }
        static bool IsPrime(long num)
        {
            if (num == 1) { return false; }
            for (long i = 2; i <= Sqrt(num) + 1; i++) { if (num % i == 0) { return false; } }
            return true;
        }
        static void CoutAr<Type>(IEnumerable<Type> types) { Cout(string.Join(" ", types)); }
        static long nCr(int n, int r) { return nPr(n, r) / Factorial(r); }
        static long nPr(int n, int r) { return FactorialDivision(n, n - r); }
        static long FactorialDivision(int tf, int df)
        {
            long r = 1;
            for (int i = tf; i > df; i--) { r *= i; }
            return r;
        }
        static long Factorial(int i)
        {
            if (i <= 1) { return 1; }
            return i * Factorial(i - 1);
        }
        static void CoutMemPairAr<Type>(IEnumerable<Pair<Type>> pairs)
        {
            var ar = pairs.ToArray();
            for (int i = 0; i < ar.Length; i++) { Write($"({ar[i].a}, {ar[i].b}, {ar[i].c}), "); }
            Cout("");
        }
    }
    public struct Pair<T>
    {
        public T a, b, c;
        public Pair(T _a, T _b, T _c = default(T)) { a = _a; b = _b; c = _c; }
    }
}


Measured memory_bytes: 18372