using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static bool DEBUG = false;



        static void Main(string[] args)
        {
            do
            {
                Output.Sb.Clear();

                try
                {
                    Solve();
                    Console.WriteLine(Output.Sb.ToString());
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e);
                }

            } while (DEBUG);
        }

        // 回答
        private static void Solve()
        {
            Input.Get(out int N);

            Output.AppendLine(((N / 1000 + 1) * 1000 - N) % 1000);
        }
    }

    // 入力
    static class Input
    {
        public static void Get(out string in1)
        {
            in1 = Console.ReadLine();
        }

        public static void Get(out int in1)
        {
            in1 = int.Parse(Console.ReadLine());
        }

        public static void Get(out int in1, out int in2)
        {
            var arn = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
            in1 = arn[0];
            in2 = arn[1];
        }

        public static void Get(out int in1, out int in2, out int in3)
        {
            var arn = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
            in1 = arn[0];
            in2 = arn[1];
            in3 = arn[2];
        }

        public static void Get(out string[] in1)
        {
            in1 = Console.ReadLine().Split(' ');
        }

        public static void Get(out int[] in1)
        {
            in1 = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
        }

        public static void Get(out List<string> in1)
        {
            in1 = Console.ReadLine().Split(' ').ToList();
        }

        public static void Get(out List<int> in1)
        {
            in1 = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
        }

    }

    // 出力用StringBuilder拡張メソッド
    static class Output
    {
        public static StringBuilder Sb { get; } = new StringBuilder();

        public static void AppendLine(int value)
        {
            Sb.AppendLine(value.ToString());
        }

        public static void AppendDebug<T>(string title, T[] arr)
        {
            if (!Program.DEBUG)
            {
                return;
            }

            Sb.AppendLine($"{title}[{arr.Length}]");

            Sb.AppendLine($"[{string.Join(", ", arr.Select(item => item.ToString()))}]");

            Sb.AppendLine();
        }

        public static void AppendDebug<T>(string title, T[][] arr)
        {
            if (!Program.DEBUG)
            {
                return;
            }

            Sb.AppendLine($"{title}[{arr.Length}][{(arr.Length > 0 ? arr[0].Length : 0)}]");

            foreach (var row in arr)
            {
                Sb.AppendLine($"[{string.Join(", ", row.Select(item => item.ToString()))}]");
            }


            Sb.AppendLine();
        }
    }
}


Measured memory_bytes: 27520