Problem:
Score : 700 points

Problem Statement

Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Constraints

2 \leq K \leq 10^5

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Sample Input 1

6

Sample Output 1

3

12=6×2 yields the smallest sum.

Sample Input 2

41

Sample Output 2

5

11111=41×271 yields the smallest sum.

Sample Input 3

79992

Sample Output 3

36

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;

namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramD a = new ProgramD();
            a.main();

        }
    }

    //ABC077
    class ProgramA
    {
        public void main()
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }

    class ProgramB
    {
        public void main()
        {
            long n = long.Parse(Console.ReadLine());
            for (long i = 1; i < 100000; i++)
            {
                if (i * i > n)
                {
                    Console.WriteLine((i - 1) * (i - 1));
                    return;
                }

            }
        }
    }

    //ABC162
    class ProgramC
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());
            long[] a = new long[n];
            long[] b = new long[n];
            long[] c = new long[n];

            string[] s1 = Console.ReadLine().Split(' ');
            string[] s2 = Console.ReadLine().Split(' ');
            string[] s3 = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                a[i] = long.Parse(s1[i]);
                b[i] = long.Parse(s2[i]);
                c[i] = long.Parse(s3[i]);
            }

            if (n == 1)
            {
                if (a[0] < b[0] && b[0] < c[0])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
                return;
            }

            //ソートする
            Array.Sort(a);
            Array.Sort(b);
            Array.Sort(c);
            long ans = 0;

            for (int i = 0; i < n; i++)
            {
                //aの二分探索(bより小さいものを探す）
                long ans1 = 0;

                //検索範囲をこうしないとmax = 0からnとn種類の答えが取れない
                long min = -1;
                long max = n;
                
                while(min + 1 != max)
                {
                    long temp = (max + min) / 2;
                    if (a[temp] < b[i])
                        min = temp;
                    else
                        max = temp;
                }

                ans1 = min + 1;

                //cの二分探索（bより大きいものを探す）
                long ans2 = 0;
                //検索範囲をこうしないとmax = 0からnとn種類の答えが取れない
                min = -1;
                max = n;

                while (min + 1 != max) 
                {
                    long temp = (max + min) / 2;
                    if (c[temp] > b[i])
                        max = temp;
                    else
                        min = temp;

                }
                    
                ans2 = n - max;
                
                //答えを足す
                ans += ans1 * ans2;

            }

            Console.WriteLine(ans);
        }
    }



    class ProgramD
    {
        public void main()
        {
            long n = long.Parse(Console.ReadLine());
            long ans = 45;

            for(long i = 1;i < 1000000;i++)
            {
                string temp = (n * i).ToString();
                long num = 0;

                for(int j = 0;j < temp.Length;j++)
                {
                    num += temp[j] - '0';
                }

                ans = Math.Min(num, ans);
                

            }

            Console.WriteLine(ans);
        }

    }


}