using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Exec(args);
            // QuestionB.Main(args);
            Console.Out.Flush();
        }

        private static void Exec(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            var s = Console.ReadLine();

            var money = int.Parse(s);

            int result = 0;
            
            for (;;)
            {
                if (money > 1000)
                {
                    money -= 1000;
                }
                else
                {
                    result = 1000 - money;
                    break;
                }
            }
            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}
