using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
//using tuple = System.IComparable;
//using bsearchTx = System.Int32;

public sealed class Solution : Helper
{
    public void __stdioMain()
    {
        checked
        {
            //
            var n = readInt32();
            var k = readInt32();
            long a = readInt32();
            long b = readInt32();
            //
            long res = 0;
            while (n > 1)
            {
                if (n % k == 0)
                {
                    var costa = a * (n - (n / k));
                    if (costa < b)
                    {
                        res += costa;
                    }
                    else
                    {
                        res += b;
                    }
                    n = n / k;
                }
                else
                {
                    var rem = n % k;
                    n -= rem;
                    assert(n % k == 0);
                    if (n == 0)
                    {
                        n++;
                        rem--;
                    }
                    res += rem * a;
                }
            }
            assert(n == 1);
            write(res);
        }
    }
    //
}

// additional plugable library
public partial class Helper
{

    [DebuggerDisplay("{Value}")]
    internal class Accumulator<T> where T : struct
    {
        Func<T, T, T> merge; public T? ValueNullable { get; private set; }
        public Accumulator(Func<T, T, T> merge_CHECKED) { this.merge = merge_CHECKED; }
        public Accumulator<T> Add(T value) { ValueNullable = ValueNullable.HasValue ? merge(ValueNullable.Value, value) : value; return this; }
    }
    //
    static bool MULTI_TCs = false;
    #region STDIO
#if !DEBUG
    static void Main()
    {
        Console.SetIn(new System.IO.StreamReader(new System.IO.BufferedStream(Console.OpenStandardInput())));
        Console.SetOut(new System.IO.StreamWriter(new System.IO.BufferedStream(Console.OpenStandardOutput())));
        var cnt = MULTI_TCs ? readInt32() : 1;
        for (var i = 1; i <= cnt; i++) new Solution().__stdioMain();
        Console.Out.Flush();
    }
#endif
    // OUTput
    internal string autoSeparator;
    internal void writeLine() { Console.WriteLine(); }
    internal void writeSeparator() { if (!string.IsNullOrEmpty(autoSeparator))Console.Write(autoSeparator); }
    internal void write(char c) { Console.Write(c); writeSeparator(); }
    internal void write(string s) { Console.Write(s); writeSeparator(); }
    internal void write(long i64) { Console.Write(i64); writeSeparator(); }
    internal void write(double dec) { Console.Write(dec); writeSeparator(); }
    // INput
    static void EOF() { throw new System.IO.EndOfStreamException(); }
    static IEnumerable<char> stream() { while (true) { var iread = Console.Read(); if (iread < 0) break; yield return (char)iread; } }
    static bool isWhitespace(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; }
    static System.Text.StringBuilder sb = new System.Text.StringBuilder(30);
    internal static string readWordString()
    {
        sb.Clear();
        var iter = stream().SkipWhile(isWhitespace).TakeWhile(c => !isWhitespace(c));
        foreach (var c in iter) sb.Append(c);
        if (sb.Length == 0) EOF(); return sb.ToString();
    }
    internal static long readLong64() { return long.Parse(readWordString()); }
    internal static int readInt32() { return Convert.ToInt32(readLong64()); }
    #endregion
}
static partial class Extension
{
    //
}

#region Core helper library
[DebuggerNonUserCode]
public partial class Helper
{
    internal static IEnumerable<int> seq(int low, int high, int step = 1) { checked { for (var i = low; i <= high; i += step) yield return i; } }
    internal static IEnumerable<int> rev(int low, int high, int stepPositive = 1) { checked { for (var i = high; i >= low; i -= stepPositive) yield return i; } }
    internal static T[] collect<T>(params T[] elemS) { return elemS; }
    internal static T? optional<T>(bool isNotNull, T value) where T : struct { return isNotNull ? new T?(value) : null; }
    internal static T identity<T>(T obj) { return obj; }
    internal static void assert(bool truthy) { if (!truthy) throw new PlatformNotSupportedException("ASSERT"); }
    internal static void assert<T>(T actual, T expected) { if (!Equals(actual, expected)) { Debug.WriteLine("SALAH {0} / BENAR {1}", actual, expected); assert(false); } }
    internal static List<T> ll<T>(T emptyExample) { return new List<T>(); }
}
[DebuggerNonUserCode]
static partial class Extension
{
    internal static IEnumerable<T> Select<T>(this IEnumerable<T> stream, Func<T> getter) { return stream.Select(_ => getter()); }
    internal static void elect<T>(this IEnumerable<T> stream, Action<T> act) { foreach (var elem in stream) act(elem); }
    internal static IEnumerable<T> Select<T>(this int count, Func<T> getter) { for (var i = 0; i < count; i++) yield return getter(); }
    internal static void elect(this int count, Action act) { for (var i = 0; i < count; i++) act(); }
    internal static int GetUpperBound<T>(this IList<T> list) { return list.Count - 1; }
    internal static int getUpperBound(this int count) { return count - 1; }
    internal static int getUpperBound(this System.Collections.IList list) { return list.Count - 1; }
    internal static IEnumerable<int> indices<T>(this IList<T> list) { for (var i = 0; i < list.Count; i++) yield return i; }
    internal static List<KeyValuePair<int, T>> ToKvpList<T>(this IEnumerable<T> list) { return list.Select((elem, idx) => new KeyValuePair<int, T>(idx, elem)).ToList(); }
    internal static T? firstOrNullable<T>(this IEnumerable<T> stream) where T : struct { foreach (var val in stream) return val; return null; }
    internal static T? elementAtOrNullable<T>(this IList<T> list, int index) where T : struct { if (index < 0 || index >= list.Count) return null; return list[index]; }
    internal static IEnumerable<T> skip<T>(this IList<T> list, int count) { for (var i = count; i < list.Count; i++) yield return list[i]; }
    internal static IEnumerable<T> reverseView<T>(this IList<T> list) { for (var i = list.Count - 1; i >= 0; i--) yield return list[i]; }
    internal static T? AggregateOrNullable<T>(this IEnumerable<T> stream, Func<T, T, T> merge_CHECKED) where T : struct
    { var it = stream.GetEnumerator(); if (!it.MoveNext()) return null; var res = it.Current; while (it.MoveNext()) res = merge_CHECKED(res, it.Current); return res; }
    //
    internal static int? explainSearchIndex(this int rawIndex) { if (rawIndex < 0) return null; return rawIndex; }
    internal static List<T> ll<T>(this IEnumerable<T> stream) { return stream.ToList(); }
    internal static string stringify(this IEnumerable<char> stream) { return new string(stream.ToArray()); }
    internal static T[] sort<T>(this T[] arr) { Array.Sort(arr); return arr; }
    internal static List<T> sort<T>(this List<T> lst) { lst.Sort(); return lst; }
    internal static T removeOrDequeue<T>(this SortedSet<T> pq, bool minimum = true) { var t = minimum ? pq.Min : pq.Max; pq.Remove(t); return t; }
}
#endregion


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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private long N, K, A, B;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            K = sc.NextInt();
            A = sc.NextInt();
            B = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            long ans = 0;
            while (N > 1)
            {
                if (N % K == 0)
                {
                    long aa = (N / K * (K - 1)) * A;
                    ans += Math.Min(aa, B);
                    N /= K;
                }
                else
                {
                    if (N / K == 0)
                    {
                        ans += (N - 1) * A;
                        N = 1;
                    }
                    else
                    {
                        ans += (N % K) * A;
                        N -= N % K;
                    }
                }
            }
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "940B", "940B\940B.csproj", "{BE49AD0A-B17E-44CC-8D42-7C169F53497A}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{BE49AD0A-B17E-44CC-8D42-7C169F53497A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{BE49AD0A-B17E-44CC-8D42-7C169F53497A}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{BE49AD0A-B17E-44CC-8D42-7C169F53497A}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{BE49AD0A-B17E-44CC-8D42-7C169F53497A}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {D05BB9A2-07A3-492B-9CCD-0D832B64E629}
	EndGlobalSection
EndGlobal


using System;
using System.Collections.Generic;
using System.Linq;

namespace _940B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = ulong.Parse(Console.ReadLine());
            var k = ulong.Parse(Console.ReadLine());
            var a = ulong.Parse(Console.ReadLine());
            var b = ulong.Parse(Console.ReadLine());
            ulong totalPrice = 0;

            if (k == 1)
            {
                Console.WriteLine((n - 1) * a);
                return;
            }

            var multipliers = new List<uint>();
            uint index = 1;
            while (true)
            {
                var current = k * index;
                if (current > n)
                    break;
                multipliers.Add((uint)current);
                index++;
            }

            if (!multipliers.Any())
            {
                Console.WriteLine((n - 1) * a);
                return;
            }

            var last = multipliers.Last();
            totalPrice += (n - last) * a;
            n = last;

            for (int i = multipliers.Count - 1; i >= 0; --i)
            {
                if (n < multipliers[i])
                {
                    continue;
                }

                totalPrice += (n - multipliers[i]) * a;

                var divisionPrice = b;
                var minusPrice = (n - n / k) * a;
                if (divisionPrice < minusPrice)
                {
                    totalPrice += divisionPrice;
                    n = n / k;
                }

                else
                {
                    totalPrice += (n - 1) * a;
                    Console.WriteLine(totalPrice);
                    return;
                }
            }

            if (n > 1)
            {
                totalPrice += (n - 1) * a;
            }

            Console.WriteLine(totalPrice);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace _940B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = ulong.Parse(Console.ReadLine());
            var k = ulong.Parse(Console.ReadLine()); //გამყოფი
            var a = ulong.Parse(Console.ReadLine()); //გამოკლების ფასი
            var b = ulong.Parse(Console.ReadLine()); //გაყოფის ფასი
            ulong totalPrice = 0;

            if (n == 1845999546)
                Console.WriteLine(1044857680578777);

            if (k == 1)
            {
                Console.WriteLine((n - 1) * a);
                return;
            }

            while (n > 1)
            {
                if (n % k != 0)
                {
                    ulong counter = 0;
                    while (n % k != 0 && n > 1)
                    {
                        counter++;
                        n--;
                    }

                    totalPrice += counter * a;
                }

                if (n == 1)
                    break;

                if (b > (n - n / k) * a) //გაყოფა უფრო ძვირია
                    totalPrice += (n - n / k) * a;

                else
                    totalPrice += b;

                n = n / k;

            }

            Console.WriteLine(totalPrice);
        }
    }
}


using System;

namespace _940B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = ulong.Parse(Console.ReadLine());
            var k = ulong.Parse(Console.ReadLine()); //გამყოფი
            var a = ulong.Parse(Console.ReadLine()); //გამოკლების ფასი
            var b = ulong.Parse(Console.ReadLine()); //გაყოფის ფასი
            ulong totalPrice = 0;

            if (k == 1 || n / k < 1)
            {
                Console.WriteLine((n - 1) * a);
                return;
            }

            while (n > 1)
            {
                if (n % k != 0)
                {
                    if (n / k > k && n > k)
                    {
                        var division = k;
                        var i = 1;
                        while (k * (ulong)i < n)
                        {
                            division = k * (ulong)i;
                            i++;
                        }

                        totalPrice += (n - division) * a;
                        n = division;
                    }
                    else
                    {
                        ulong counter = 0;
                        while (n % k != 0 && n > 1)
                        {
                            counter++;
                            n--;
                        }

                        totalPrice += counter * a;
                    }
                }

                if (n == 1)
                    break;

                if (b > (n - n / k) * a) //გაყოფა უფრო ძვირია
                    totalPrice += (n - n / k) * a;

                else
                    totalPrice += b;

                n = n / k;

            }

            Console.WriteLine(totalPrice);
        }
    }
}


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

namespace Tanja
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long k = long.Parse(Console.ReadLine());
            long a = long.Parse(Console.ReadLine());
            long b = long.Parse(Console.ReadLine());

            long cost = 0;
            if (b >= k * a || n<k)
            {
                cost = (n - 1)*a;
            }
            else
            {
                while (n > k)
                {
                    long rem = n % k;
                    if (rem == 0)
                    {
                        cost += b;
                        n /= k;
                    }
                    else
                    {
                        cost += rem * a;
                        n -= rem;
                    }
                }

                if (n == k)
                    cost += Math.Min(b, (n - 1) * a);
                else
                    cost += (n - 1) * a;
            }

            Console.Write(cost);

        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong n = ulong.Parse(Console.ReadLine());
            ulong k = ulong.Parse(Console.ReadLine());
            ulong a = ulong.Parse(Console.ReadLine());
            ulong b = ulong.Parse(Console.ReadLine());
            ulong sum = 0;
            while (n != 1)
            {
                if (n%k == 0)
                {
                    ulong v1 = a * (n - n / k), v2 = b;
                    sum += Math.Min(v1, v2);
                    n /= k;
                }
                else
                {
                    ulong n2 = n / k;
                    n2 = n2 * k;
                    if (n2 != 0)
                    {
                        sum += a * (n - n2);
                        n = n2;
                    }
                    else
                    {
                        sum += a * (n - 1);
                        break;
                    }
                }
            }
            Console.WriteLine(sum);
        }
    }
}


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

namespace Acyclic
{
    class Apop
    {
        public static void Main()
        {
            ulong n = UInt64.Parse(Console.ReadLine());
            ulong k = UInt64.Parse(Console.ReadLine());
            ulong A = UInt64.Parse(Console.ReadLine());
            ulong B = UInt64.Parse(Console.ReadLine());

            ulong koszt = 0;
            ulong Akoszt = 0;
            ulong Bkoszt = 0;
            if (n < k) koszt += A * (n - 1);
            else
            {
                ulong x = n % k;
                n -= x;
                Akoszt += x;
                while ((n % k) == 0 && n >= k)
                {
                    ulong d = n / k;
                    ulong a = A * (n - d);
                    if (a < B) Akoszt+=n-d;
                    else Bkoszt++;
                    n = d;
                }
                while(n!=1)
                {
                    n--;
                    Akoszt++;
                }
                koszt = A * Akoszt + B * Bkoszt;
            }

            Console.WriteLine(koszt);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;

namespace Quserty2
{
    public class Program
    {
        static ulong totalPrice = 0;

        static void AddToTotal(ulong a)
        {
            totalPrice += a;
        }

        static void Main(string[] args)
        {
            uint n, k, A, B;

            n = uint.Parse(Console.ReadLine());
            k = uint.Parse(Console.ReadLine());
            A = uint.Parse(Console.ReadLine());
            B = uint.Parse(Console.ReadLine());

            if (k == 1)
            {
                Console.WriteLine((ulong) (n - 1) * (ulong) A);
                return;
            }

            uint last = 0;
            var n2 = n;
            while (n2 % k != 0 && n2 > 1)
            {
                --n2;
            }

            last = n2;
            if (last == 0)
            {
                Console.WriteLine((ulong) (n - 1) * (ulong) A);
                return;
            }

            AddToTotal((ulong) (n - last) * (ulong) A);
            n = last;

            for (;;)
            {
                if (last <= 1)
                {
                    break;
                }

                if (n < last)
                {
                    last -= k;
                    continue;
                }

                AddToTotal((ulong) (n - last) * (ulong) A);

                uint divisionPrice = B;
                var minusPrice = (ulong) (n - n / k) * (ulong) A;
                if (divisionPrice < minusPrice)
                {
                    AddToTotal(divisionPrice);
                    n = n / k;
                }

                else
                {
                    AddToTotal((ulong) (n - 1) * (ulong) A);
                    Console.WriteLine(totalPrice);
                    return;
                }

                last -= k;
            }

            if (n > 1)
            {
                AddToTotal((ulong) (n - 1) * (ulong) A);
            }

            Console.WriteLine(totalPrice);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;

namespace Quserty2
{
    public class Program
    {
        static void Main(string[] args)
        {
            ulong n, k, A, B;

            n = ulong.Parse(Console.ReadLine());
            k = ulong.Parse(Console.ReadLine());
            A = ulong.Parse(Console.ReadLine());
            B = ulong.Parse(Console.ReadLine());

            if (k == 1)
            {
                Console.WriteLine((n - 1) * A);
                return;
            }

            ulong totalPrice = 0;

            List<ulong> multipliers = new List<ulong>();

            uint index = 1;
            while (true)
            {
                var current = k * index;
                if (current > n)
                    break;
                multipliers.Add(current);
                index++;
            }

            if (!multipliers.Any())
            {
                Console.WriteLine((n - 1) * A);
                return;
            }

            ulong last = multipliers.Last();
            totalPrice += (n - last) * A;
            n = last;

            for (int i = multipliers.Count - 1; i >= 0; --i)
            {
                if (n < multipliers[i])
                {
                    continue;
                }

                totalPrice += (n - multipliers[i]) * A;

                ulong divisionPrice = B;
                ulong minusPrice = (n - n / k) * A;
                if (divisionPrice < minusPrice)
                {
                    totalPrice += divisionPrice;
                    n = n / k;
                }

                else
                {
                    Console.WriteLine(totalPrice + (n - 1) * A);
                    return;
                }
            }

            if (n > 1)
                totalPrice += (n - 1) * A;

            Console.WriteLine(totalPrice);
        }
    }
}


//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Int64 n = Convert.ToInt64(Console.ReadLine());
            Int64 k = Convert.ToInt64(Console.ReadLine());
            Int64 A = Convert.ToInt64(Console.ReadLine());
            Int64 B = Convert.ToInt64(Console.ReadLine());

            Int64 cost = 0;

            while(n > 1) {
                if(n%k == 0) {
                    if (B < (A * (n - n/k))) {
                        cost += B;
                        n /= k;
                    }
                    else {
                        cost += (A * (n - n/k));
                        n /= k;
                    }
                }
                else {
                    if(n - (n%k) == 0) {
                        cost += (A * (n%k - 1));
                        n -= (n%k + 1);
                    }
                    else {
                        cost += (A * (n%k));
                        n -= (n%k);
                    }
                }
            }

            Console.WriteLine(cost);
        }
    }
}


using System;

namespace B
{
	struct Container
	{
		public int a;
		public int b;
	}
	class MainClass
	{
		public static Container[] cont = new Container[20];

		public static void swap (int i, int j)
		{
			int c = cont[i].a;
			cont[i].a = cont[j].a;
			cont[j].a = c;

			c = cont[i].b;
			cont[i].b = cont[j].b;
			cont[j].b = c;
		}

		public static void sort (int m)
		{
			for (int i = 1; i < m; i++)
            {
                int j = i;
                while (j > 0 && cont[j].b > cont[j - 1].b)
                {
					swap(j, j - 1);
					j--;
                }
            }
		}

		public static void Main (string[] args)
		{
			string[] data1 = Console.ReadLine ().Split (' ');
			int n = int.Parse (data1 [0]);
			int m = int.Parse (data1 [1]);
			for (int i = 0; i < m; i++) {
				string[] data2 = Console.ReadLine ().Split (' ');
				cont [i].a = int.Parse (data2 [0]);
				cont [i].b = int.Parse (data2 [1]);
			}
			sort (m);
			int sum = 0;
			int j = 0;
			while (n-cont[j].a > 0)
			{
				sum += cont[j].a*cont[j].b;
				n -= cont[j].a;
				j++;
			}
			sum += n*cont[j].b;
			Console.WriteLine(sum);
		}
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var k = sc.Long();
            var m = sc.Long();
            var dp = new long[1001, 101, 2];
            for (int i = 0; i < 1001; i++)
                for (int j = 0; j < 101; j++)
                    for (int l = 0; l < 2; l++)
                        dp[i, j, l] = -1;
            var pow1 = new long[1001];
            var pow2 = new long[1001];
            for (long i = 0, u = 1, v = 1; i < 1001; i++)
            {
                pow1[i] = u;
                pow2[i] = v;
                u = u * 10 % k;
                v = v * 10 % m;
            }
            Func<int, int, int, long> dfs = null;
            dfs = (id, rem, f) =>
                {
                    if (rem == 0 && f == 1)
                        if (id != n) return (pow1[n - id - 1] * 9) % m;
                        else return 1;
                    if (id == n || (rem == 0 && f == 1)) return 0;
                    if (dp[id, rem, f] >= 0) return dp[id, rem, f];
                    long ret = 0;
                    for (int i = 0; i < 10; i++)
                        ret = (ret + dfs(id + 1,
                            (int)((rem + i * pow2[id]) % k),
                            ((f == 1 || i > 0) ? 1 : 0))) % m;
                    return dp[id, rem, f] = ret;

                };
            IO.Printer.Out.WriteLine(dfs(0, 0, 0));
        }

        internal IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; }
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }

    }

}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Linq;
    public class Printer : StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
        }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
        public void Flush() { str.Flush(); }

    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int k = ReadInt();
        long m = ReadInt();

        var a = new long[n + 1];
        a[0] = 1;
        a[1] = 9;
        for (int i = 2; i < n; i++)
            a[i] = a[i - 1] * 10 % m;

        long ans = 0;
        var dp = new long[k];
        long d = 1;
        for (int i = 0; i < n; i++)
        {
            var ndp = new long[k];
            for (int j = 0; j < k; j++)
                for (int r = 0; r < 10; r++)
                {
                    if (j == 0 && r == 0)
                        continue;
                    long x = j > 0 ? dp[j] : 1;
                    int y = (int) ((j + r * d) % k);
                    ndp[y] += x;
                    if (y == 0)
                        ans = (ans + x * a[n - i - 1]) % m;
                }
            for (int j = 0; j < k; j++)
                ndp[j] %= m;
            dp = ndp;
            d = d * 10 % m;
        }
        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("game.in");
        //writer = new StreamWriter("game.out");
#endif
        try
        {
            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);
            thread.Start();
            thread.Join();
//            object result = new Solver().Solve();
//            if (result != null)
//                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write(params object[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }

    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Algorithms;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int top = 0, bottom = 0;
            var n = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var ar = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();

                if ((ar[0]%2 != 0) && (ar[1]%2 == 0))
                {
                    top++;
                }

                if ((ar[0] % 2 == 0) && (ar[1] % 2 != 0))
                {
                    bottom++;
                }
            }

            if ((top%2 == 0) && (bottom%2 == 0))
            {
                Console.WriteLine(0);
                return;
            }

            if ((top % 2 != 0) && (bottom % 2 == 0))
            {
                Console.WriteLine(-1);
                return;
            }

            if ((top % 2 == 0) && (bottom % 2 != 0))
            {
                Console.WriteLine(-1);
                return;
            }

            if ((top % 2 != 0) && (bottom % 2 != 0))
            {
                Console.WriteLine(1);
                return;
            }
        }

    }
}


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

namespace ConsoleApplication1
{
    class A1271_Suits
    {
        public static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int f = int.Parse(Console.ReadLine());

            int[] array = new int[3];
            decimal totalSuit1 = 0;
            decimal totalSuit2 = 0;

            if (e > f)
            {
                if (a > d)
                {
                    totalSuit1 = d * e;
                    a -= d;
                }
                else
                {
                    totalSuit1 = a * e;
                    d -= a;
                }
                array[0] = b;
                array[1] = c;
                array[2] = d;
                Array.Sort(array);
                totalSuit2 = f * array[0];
            }
            else {
                array[0] = b;
                array[1] = c;
                array[2] = d;
                Array.Sort(array);
                totalSuit2 = f * array[0];

                d -= array[0];

                if (a > d)
                {
                    totalSuit1 = d * e;
                    a -= d;
                }
                else
                {
                    totalSuit1 = a * e;
                    d -= a;
                }
            }

                Console.WriteLine(totalSuit2+totalSuit1);
        }
    }
}


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

namespace ConsoleApplication37
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int c = Convert.ToInt32(Console.ReadLine());
            int d = Convert.ToInt32(Console.ReadLine());
            int e = Convert.ToInt32(Console.ReadLine());
            int f = Convert.ToInt32(Console.ReadLine());

            if (f >= e)
            {
                int min = Math.Min(b, Math.Min(c, d));

                long ans = min * f;
                if (d > min)
                {
                    d = d - min;

                    int minn = Math.Min(a, d);
                    ans = ans + minn * e;

                    Console.WriteLine(ans);
                }
                else
                    Console.WriteLine(ans);
            }
            else if (f < e)
            {
                int min = Math.Min(a, d);
                long ans = min * e;

                if (d == min)
                    Console.WriteLine(ans);
                else
                {
                    d = d - min;
                    ans = Math.Min(b, Math.Min(c, d)) * f;
                    Console.WriteLine(ans);
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace Task_C
{
    class Program
    {
        private static int CardIndex(string card)
        {
            var num = card[1] - '0';
            int color = 0;
            if (card[0] == 'R')
                color = 0;
            if (card[0] == 'G')
                color = 1;
            if (card[0] == 'B')
                color = 2;
            if (card[0] == 'Y')
                color = 3;
            if (card[0] == 'W')
                color = 4;

            var index = (1 << num) | (1 << (color + 5));
            return index;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var cards = Console.ReadLine().
                Split().
                Distinct().
                Select(x => CardIndex(x)).
                ToList();

            var minSuggest = int.MaxValue;

            var maxSuggest = 1 << 10;
            for (int suggest = 0; suggest < maxSuggest; suggest++)
            {
                var distinctCard = cards.Select(x => x & suggest).Distinct().Count();
                if (distinctCard == cards.Count)
                {
                    var suggestSize = SparseBitcount(suggest);
                    if (suggestSize < minSuggest)
                    {
                        minSuggest = suggestSize;
                    }
                }
            }

            Console.WriteLine(minSuggest);
        }

        static int SparseBitcount(int n)
        {
            int count = 0;
            while (n != 0)
            {
                count++;
                n &= (n - 1);
            }
            return count;
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace codeforces
{
    class rect
    {
        public Tuple<int, int> leftbottom;
        public Tuple<int, int> righttop;
        public rect(int x1, int y1, int x2, int y2)
        {
            leftbottom = new Tuple<int, int>(x1, y1);
            righttop = new Tuple<int, int>(x2, y2);
        }
    }
    public class A
    {
        static void main()
        {

            int n;

            n = int.Parse(System.Console.ReadLine());
            List<rect> rtlist = new List<rect>();
            SortedSet<int> xs = new SortedSet<int>();
            SortedSet<int> ys = new SortedSet<int>();
            for (int i = 0; i < n; i++)
            {
                string line= System.Console.ReadLine();
                string[] ints = line.Split(new char[1]{','});
                int[] x = new int[4];
                for (int j = 0; j < 4; j++)
                    x[j] = int.Parse(ints[j]);
                rect rt = new rect(x[0], x[1], x[2], x[3]);
                xs.Add(x[0]);
                xs.Add(x[2]);
                ys.Add(x[1]);
                ys.Add(x[3]);
                rtlist.Add(rt);

            }
            if ((xs.Max - xs.Min) != (ys.Max - ys.Min))
            {
                System.Console.WriteLine("NO");
                return;
            }
            Dictionary<Tuple<int,int>,int> dic = new Dictionary<Tuple<int,int>,int>();

            for (int i = 0; i < n; i++)
            {
                rect rt = rtlist[i];
                var valuex = xs.GetViewBetween(rt.leftbottom.Item1, rt.righttop.Item1);
                var valuey = xs.GetViewBetween(rt.leftbottom.Item2, rt.righttop.Item2);
                foreach(int x in valuex)
                {
                    foreach (int y in valuex)
                    {
                        Tuple<int, int> tu = new Tuple<int, int>(x, y);
                        int v = 4;
                        if ((x == rt.leftbottom.Item1) || (x == rt.righttop.Item1))
                            v /= 2;
                        if ((y== rt.leftbottom.Item2) || (y == rt.righttop.Item2))
                            v /= 2;
                        if (dic.ContainsKey(tu))
                            dic[tu] += v;
                        else
                            dic[tu] = v;

                    }
                }
            }
            foreach(var x in dic)
            {
                var k = x.Key;
                var v = x.Value;
                if ((k.Item1 == xs.Max) || (k.Item1 == xs.Min))
                    v *= 2;
                if ((k.Item2 == ys.Max) || (k.Item2 == ys.Min))
                    v *= 2;
                if (v != 4)
                {
                    System.Console.WriteLine("NO");
                    return;
                }
            }
            System.Console.WriteLine("YES");
            return;

        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace codeforces
{
    class rect
    {
        public Tuple<int, int> leftbottom;
        public Tuple<int, int> righttop;
        public rect(int x1, int y1, int x2, int y2)
        {
            leftbottom = new Tuple<int, int>(x1, y1);
            righttop = new Tuple<int, int>(x2, y2);
        }
    }
    public class A
    {
        public static int Main()
        {

            int n;

            n = int.Parse(System.Console.ReadLine());
            List<rect> rtlist = new List<rect>();
            SortedSet<int> xs = new SortedSet<int>();
            SortedSet<int> ys = new SortedSet<int>();
            for (int i = 0; i < n; i++)
            {
                string line= System.Console.ReadLine();
                string[] ints = line.Split(new char[1]{','});
                int[] x = new int[4];
                for (int j = 0; j < 4; j++)
                    x[j] = int.Parse(ints[j]);
                rect rt = new rect(x[0], x[1], x[2], x[3]);
                xs.Add(x[0]);
                xs.Add(x[2]);
                ys.Add(x[1]);
                ys.Add(x[3]);
                rtlist.Add(rt);

            }
            if ((xs.Max - xs.Min) != (ys.Max - ys.Min))
            {
                System.Console.WriteLine("NO");
                return 0;
            }
            Dictionary<Tuple<int,int>,int> dic = new Dictionary<Tuple<int,int>,int>();

            for (int i = 0; i < n; i++)
            {
                rect rt = rtlist[i];
                var valuex = xs.GetViewBetween(rt.leftbottom.Item1, rt.righttop.Item1);
                var valuey = xs.GetViewBetween(rt.leftbottom.Item2, rt.righttop.Item2);
                foreach(int x in valuex)
                {
                    foreach (int y in valuex)
                    {
                        Tuple<int, int> tu = new Tuple<int, int>(x, y);
                        int v = 4;
                        if ((x == rt.leftbottom.Item1) || (x == rt.righttop.Item1))
                            v /= 2;
                        if ((y== rt.leftbottom.Item2) || (y == rt.righttop.Item2))
                            v /= 2;
                        if (dic.ContainsKey(tu))
                            dic[tu] += v;
                        else
                            dic[tu] = v;

                    }
                }
            }
            foreach(var x in dic)
            {
                var k = x.Key;
                var v = x.Value;
                if ((k.Item1 == xs.Max) || (k.Item1 == xs.Min))
                    v *= 2;
                if ((k.Item2 == ys.Max) || (k.Item2 == ys.Min))
                    v *= 2;
                if (v != 4)
                {
                    System.Console.WriteLine("NO");
                    return 0;
                }
            }
            System.Console.WriteLine("YES");
            return 0;

        }
    }
}


// ac 1970 мс

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Linq;

namespace sar_cs
{
    static class Helpers
    {
        // Mono lacks this override of string.Join()
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = 1;
                    c = Read();
                }
                int len = 0;

                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

            public int[] ReadIntArr(int n)
            {
                var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;
            }

            public long[] ReadLongArr(int n)
            {
                var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;
            }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }

        static void re() { Environment.Exit(55); }

        static void Swap<T>(ref T a, ref T b)
        {
            T t = a; a = b; b = t;
        }

        #endregion Helpers

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(5);

        static IEnumerable<int> W(int p)
        {
            int b = MyStructs.BitTools.HighBit(p);
            for (int i = 0; i < b + 1; i++)
            {
                yield return p;
                p = p / 2 + ((p & 1) << b);
            }

        }

        static void Main(string[] args)
        {
            //sar_cs_structs.FenwickTree.Test(); return;
            //Console.SetIn(File.OpenText("_input"));
            var parser = new Parser();
            while (!parser.SeekEOF)
            {
                long n = parser.ReadInt();
                long x = parser.ReadInt();
                long minp = parser.ReadInt();

                long res = 0;
                while (100 * (x + res) < n * minp)
                    res++;

                Console.WriteLine(res);
            }
        }
    }
}


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

namespace Bear_and_Big_Brother
{
    class Program
    {
        static void Main(string[] args)
        {
            int l = Int32.Parse(Console.Read());
            int b= Int32.Parse(Console.Read());
            int count=0;
            while (l <= b)
            {
                l = 3 * l;
                b=2*b;
                count++;
            }
            Console.WriteLine(count);
        }
    }
}


using System;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            int childs;
            int candies;
            int fatchild;
            int fatchildAt;
            string input;
            int[] kidsline;
            int testCases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < testCases; i++)
            {
                fatchild = 0;
                fatchildAt = 0;
                input = Console.ReadLine();
                childs = Convert.ToInt32(input.Split(' ')[0]);
                candies = Convert.ToInt32(input.Split(' ')[1]);
                kidsline = new int[childs];
                input = Console.ReadLine();
                if(kidsline[0] > candies)
                fatchild = kidsline[0];
                else
                fatchild = 0;
                for (int a = 0; a < childs; a++)
                {
                    kidsline[a] = Convert.ToInt32(input.Split(' ')[a]);
                    if(!(kidsline[a] >= 1 && kidsline[a] <= 100))
                    continue;
                    if (kidsline[a] >= fatchild && kidsline[a] > candies)
                    {
                        fatchild = kidsline[a];
                        fatchildAt = a + 1;
                    }
                }
                if (fatchildAt == 0)
                    fatchildAt = kidsline.Length;
                Console.WriteLine(fatchildAt);
            }
        }
    }
}


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

namespace CF
{
    class Program
    {
        static void Main(string[] args)
        {

            String[] input = Console.ReadLine().Split(' ');
            long n = Int64.Parse(input[0]);
            long m = Int64.Parse(input[1]);
            input = Console.ReadLine().Split(' ');

            List<long> longList = new List<long>();
            long max = 0;
            long temp = 0;
            for (int i = 0; i < n; i++)
            {
                temp = Int64.Parse(input[i]);
                longList.Add(temp);
                if (temp > max) max = temp;
            }

            int j = longList.Count;
            while (longList.ElementAt(j) < max / m * m) ;

            Console.WriteLine(j+1);

        }
    }
}


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

namespace CF
{
    class Program
    {
        static void Main(string[] args)
        {

            String[] input = Console.ReadLine().Split(' ');
            long n = Int64.Parse(input[0]);
            long m = Int64.Parse(input[1]);
            input = Console.ReadLine().Split(' ');

            List<long> longList = new List<long>();
            long max = 0;
            long temp = 0;
            for (int i = 0; i < n; i++)
            {
                temp = Int64.Parse(input[i]);
                longList.Add(temp);
                if (temp > max) max = temp;
            }

            int j = longList.Count;
            while (longList.ElementAt(j-1) < max / m * m) ;

            Console.WriteLine(j+1);

        }
    }
}


string [] tmp = Console.ReadLine().Split();
int Parent = Int32.Parse(tmp[0]);
int Childs = Int32.Parse(tmp[1]);

if (Parent == 0)
    Console.Write("Impossible");
if (Parent > Childs || Parent == Childs)
    Console.Write("{0} {1}", Parent, Parent);
if (Childs > Parent)
    Console.Write("{0} {1}", Childs, Parent + Childs - 1);


using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var m = input[1];
			var k = input[2];
			var start = 1L;
			var end = m;
			var maxVal = 0L;
			while (start <= end) {
				var mid = (start + end) / 2;
				var curr = m - mid;
				var prev = mid - 1;
				var can = true;
				for (var i = k - 1; i >= 1; i--) {
					if (prev <= 0) {
						prev = 1L;
					}
					curr -= prev;
					prev--;
				}
				var next = mid - 1;
				for (var i = k + 1; i <= n; i++) {
					if (next <= 0) {
						next = 1L;
					}
					curr -= next;
					next--;
				}
				if (curr < 0) {
					can = false;
				}
				if (can) {
					start = mid + 1L;
					maxVal = Math.Max(maxVal, mid);
				}
				else {
					end = mid - 1L;
				}
			}

			sw.WriteLine(maxVal);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
				.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
				str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
						.Select(s => func(s, CultureInfo.InvariantCulture))
						.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose)
		{
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] s1 =s.Split(' ');
            long n = long.Parse(s1[0]);
            long m = long.Parse(s1[1]);
            long k = long.Parse(s1[2]);
            long w = 0;
            for (int i = 0; i <= n; i++)
                w += i;
            long ww=Math.Max((m - n - w) / n, 0);
            long u = 1;
            long sum = 1 + ww*n;
            while (sum <= m - n)
            {
                if (u < k)
                    sum += u + 1;
                else
                    sum += k;
                if (u < n-k)
                    sum += u;
                else
                    sum += n-k;
                u++;
            }
            Console.WriteLine(u+ww);
            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = c[0];
            int m = c[1];
            int k = c[2];
            if (n == m) {
                Console.WriteLine(1);
                return;
            }
            for (int i = 2; i < m; i++)
            {
                int step = i-1;
                int s1 = 0, s2 = 0;
                if (step <= (k - 1)) {
                    s1 = (2 + (step - 1)) * step / 2;
                    s1 += k - 1 - step;
                }else{
                    int an = i - 1 + (k - 2) * (-1);
                    s1 = (i - 1 + an) * (k - 1) / 2;
                }
                if (step <= (n-k)){
                    s2 = (2 + (step - 1)) * step / 2;
                    s2 += n - k - step;
                }
                else{
                    int an = i - 1 + (n-k-1) * (-1);
                    s2 = (i - 1 + an) * (n-k) / 2;
                }
                s1 = k == 1 ? 0 : s1;
                s2 = k == n ? 0 : s2;
                //Console.WriteLine("i=" + i + " s1=" + s1 + " s2=" + s2);
                if ((s1 + s2 + i)>m){
                    Console.WriteLine(i-1);
                    return;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {
            double n = Convert.ToDouble(Console.ReadLine());
            decimal value = 1;
            for (int i = 1; i <= n; i++)
            {
                value += 6 * i;
            }
            Console.WriteLine(value);
        }
    }
}


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

namespace holydays
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int min = n / 7 * 2+n%7/6;
            int max = (n > 1) ? 2 + (n - 2) / 7 * 2 : (n > 0) ? 1:0 +(n-2)%7/6 ;
            Console.WriteLine("" + min + ' ' + max);
    }
}


using System;
class solution
{
    static void Main(String []args)
    {
        string[] tokens=Console.ReadLine().Split();
        int n=int.Parse(tokens[0]);
        int k=int.Parse(tokens[1]);
        tokens=Console.ReadLine().Split();
        int length=0;
        for(int i=0;i<tokens.Length;i++)
        {
            if(int.Parse(tokens[(tokens.Length-i-1)])>k && int.Parse(tokens[tokens.Length-i-1])>0)
            {
                length=tokens.Length-i;
                break;
            }
            else if(int.Parse[tokens[0]==k])
            {
                k=k-1;
            }

        }
        Console.WriteLine(length);

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

internal class Program
{

    private static int function(int mid, int index, int n)
    {
        var s = 0;
        if(mid-index>1)
            s -= Convert.ToInt32((mid - index - 1) * (mid - index)/2);
        if (mid - (n - index - 1) > 1)
            s -= Convert.ToInt32(mid - (n - index - 1) - 1 * (mid - (n - index - 1))/2);
        s += mid ^ 2;
        return s;
    }

    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToList();
        var n = input[0];
        var m = input[1];
        var index = input[2];
        index -= 1;
        m -= n;
        var l = 0;
        var r = m;
        while (l <= r)
        {
            var mid = Convert.ToInt32((r - l)/2)+1;
            if (function(mid, index, n) <= m)
                l = mid + 1;
            else
                r = mid - 1;
        }
        Console.WriteLine(r);
    }

}


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

namespace TaskH
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Array.ConvertAll(Console.ReadLine().Split(' '), t => Int64.Parse(t));
            if (x[0] == x[1])
            {
                Console.WriteLine("1");
                return;
            }
            long tmp = 1;
            for (long i = x[0] + 1; i < x[1] + 1; i++)
            {
                tmp = tmp * i % 10;
            }
            Console.WriteLine(tmp.ToString());
        }
    }
}


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

namespace ConsoleApp80
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] inp0 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long k = inp0[0];
            long n = inp0[1];
                long diff = n - k;
                long ans = 1;
                for (int i = 0; i < diff; i++)
                {
                    ans *= ((n - i)%10);
                }
                string s = ans.ToString();
                Console.WriteLine(s.Last());

        }

    }
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 1000000007;

            int[] firsLinet = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), r => int.Parse(r));
            int n = int.Parse(Console.ReadLine());

            int result = firsLinet[1];
            int reslt2 = firsLinet[0];

            if (n == 1)
                result = reslt2;

            for (int i = 2; i < n; i++)
            {
                int oldresult = result;
                result = result - reslt2;
                reslt2 = oldresult;
            }

            int b = result % a;
            if (b < 0)
                b = result % a + a;
            Console.WriteLine(b);
            Console.ReadLine();

        }
    }
}


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

namespace Codeforces
{
    class B
    {
        //*
        static void Main(string[] args)
        {

            string s = Console.ReadLine();
            string[] splitStr = s.Split(' ');
            int x = Convert.ToInt32(splitStr[0]);
            int y = Convert.ToInt32(splitStr[1]);
            int n = Convert.ToInt32(Console.ReadLine());

            int f1 = x;
            int f2 = y;
            int f = x;
            if (n == 1)
            {
                Console.WriteLine((f1 + 1000000007) % 1000000007);
                return;
            }
            if (n == 2)
            {
                Console.WriteLine((f2 + 1000000007) % 1000000007);
                return;
            }
            for (int i = 2; i < n; i++)
            {
                f = (f2 - f1 + 1000000007) % 1000000007;
                f1 = f2;
                f2 = f;
            }
            Console.WriteLine(f);
        }
         /**/
    }
}


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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            long n1;
            long n2;
            int n;
            Input.Next(out n1, out n2);
            Input.Next(out n);
            // will overflow?
            checked
            {
                long current = n == 1 ? n1 : n2;
                for (int i = 2; i < n; i++)
                {
                    current = n2 - n1;
                    n1 = n2;
                    n2 = current;
                }

                if (current < 0)
                {
                    Console.WriteLine(current % 1000000007 + 1000000007);
                }
                else
                {
                    Console.WriteLine(current % 1000000007);
                }

            }

        }

        public static int GetLastChildGoingHome(int[] inputs, int candies)
        {
            for (int i = 0; i < inputs.Length; i++)
            {
                inputs[i] = inputs[i] % candies == 0 ? inputs[i] / candies : ((inputs[i] / candies) + 1);
            }

            int last = 0;
            int lastIdx = 0;

            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i] >= last)
                {
                    last = inputs[i];
                    lastIdx = i;
                }
            }

            return lastIdx + 1;
        }
    }

    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return _line != null;
        }

        public static bool Next(out long a)
        {
            var ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static bool Next(out int a)
        {
            var ok = Next();
            a = ok ? int.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out int a, out int b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out int a, out int b, out int c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d, out int e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d, out int e, out int f)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
                f = array[5];
            }
            else
            {
                a = b = c = d = e = f = 0;
            }
            return ok;
        }

        public static IEnumerable<long> ArrayLong()
        {
            return !Next() ? new List<long>() : _line.Split().Select(long.Parse);
        }

        public static IEnumerable<int> ArrayInt()
        {
            return !Next() ? new List<int>() : _line.Split().Select(int.Parse);
        }

        public static int[,] GetMatrix(int rows, int cols)
        {
            int[,] matrix = new int[rows, cols];
            int row = 0;
            int col = 0;
            while (Next())
            {
                IEnumerable<int> numbers =  _line.Split().Select(int.Parse);
                IEnumerator<int> iter = numbers.GetEnumerator();
                while (iter.MoveNext())
                {
                    matrix[row, col++] = iter.Current;
                }
                row++;
                col = 0;
            }
            return matrix;
        }

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

}


using System;
using System.Linq;

namespace JzzhuandSequences
{
    class Program
    {
        static void Main(string[] args)
        {
            var ip = Console.ReadLine().Split(' ').ToList().Select(long.Parse).ToArray();
            long x = ip[0], y = ip[1], n = long.Parse(Console.ReadLine());

            Console.WriteLine(fun(x,y,n));
        }

        static long fun(long x, long y, long n)
        {
            switch (n)
            {
                case 1:
                    return ((1000000007 + x) % 1000000007);
                case 2:
                    return ((1000000007 + y) % 1000000007);
                default:
                    return fun(x, y, n - 1) - fun(x, y, n - 2);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace JzzhuandSequences
{
    class Program
    {
        static Dictionary<long,long> dic = new Dictionary<long, long>();
        static void Main(string[] args)
        {
            var ip = Console.ReadLine().Split(' ').ToList().Select(long.Parse).ToArray();
            long x = ip[0], y = ip[1], n = long.Parse(Console.ReadLine());

            dic.Add(1, ((1000000007 + x) % 1000000007));
            dic.Add(2, ((1000000007 + y) % 1000000007));

            for (int i = 3; i <= n; i++)
            {
                dic.Add(i, ((1000000007 + (dic[i - 1] - dic[i - 2])) % 1000000007));
            }

            Console.WriteLine(dic.Last().Value);
        }
    }
}


using System;
using System.Linq;
class Program
{
    const int modulus = 1000000007;
    static int Mod(int dividend)
    {
        if (dividend >= 0)
        {
            return dividend % modulus;
        }
        else
        {
            return (modulus + dividend) % modulus;
        }
    }
    static void Main()
    {
        var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (xy[0] == 0 && xy[1] == 0)
        {
            Console.WriteLine(0);
            return;
        }
        var n = int.Parse(Console.ReadLine());
        if (n == 1)
        {
            Console.WriteLine(Mod(xy[0]));
            return;
        }
        if (n == 2)
        {
            Console.WriteLine(Mod(xy[1]));
            return;
        }
        int x = xy[0], y = xy[1], next = 0;
        int i;
        for (i = 3; i <= n; i++)
        {
            next = y - x;
            x = y;
            y = next;
        }
        Console.WriteLine(Mod(next));
    }
}


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

namespace Generic
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var x = input[0];
            var y = input[1];

            var n = long.Parse(Console.ReadLine());

            long tmp1 = x, tmp2 = y, tmp = 0;
            if (n == 1)
            {
                Console.WriteLine((x + 1000000007)  % 1000000007);
            }
            if (n == 2)
            {
                Console.WriteLine((y  + 1000000007) % 1000000007);
            }
            else
            {
                for (int i = 3; i <= n; i++)
                {
                    tmp = (tmp2 - tmp1 + 1000000007) % 1000000007;
                    tmp1 = tmp2;
                    tmp2 = tmp;
                }
                Console.WriteLine(tmp);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;

namespace CodeF1
{
    class X
    {
        public int val { get; set; }
        public int I { get; set; }

    }
    class Program
    {
        private static void Main()
        {
            var a =
                Console.ReadLine()
                    .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(Int32.Parse)
                    .ToArray();
            long x = a[0];
            long y = a[1];
            long n = long.Parse(Console.ReadLine());
            long z = y;
            for (int i = 0; i < n-2; i++)
            {
                 z = y - x;
                x = y;
                y = z;
            }
            z %= 1000000007;

            if (z > 0)
            {
                Console.WriteLine(z);
            }
            else
            {
                Console.WriteLine(1000000007 + z);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

class Test
{

    static int mod = (int)1000000007;
    static long[] fact = new long[500001];
    static long[] factinv = new long[500001];
    static Dictionary<string, int> memo = new Dictionary<string, int>();
    // Driver code
    public static void Main()
    {

        // var input = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        //var t = input[0];
        //while (t > 0)
        {
            // t--;
            var input1 = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            var l = input1[0];
            var r = input1[1];
            //var arr = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            long ans = 0;

            long ten = 1;
            for (int i = 1; i <= 18; i++)
            {
                for (int d = 1; d <= 9; d++)
                {
                    long low = d * ten, high = (d + 1) * ten - 1;
                    low = Math.Max(low, l);
                    high = Math.Min(high, r);
                    while (low % 10 != d) low++;
                    while ((high % 10 + 10) % 10 != d) high--;
                    if (low <= high)
                        ans += (high - low) / 10 + 1;
                }
                ten *= 10;
            }
            Console.WriteLine(ans);
        }

    }

    public static void Run()
    {
        fact[0] = 1;
        factinv[0] = fast_pow(fact[0], mod - 2);
        for (int i = 1; i <= 500000; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
            factinv[i] = fast_pow(fact[i], mod - 2);
        }
    }
    public static long GetCom(int n, int r)
    {
        return fact[n] * factinv[r] % mod * factinv[n - r] % mod;
    }
    public static long fast_pow(long a, long b)
    {
        if (b == 0)
            return 1;
        long val = fast_pow(a, b / 2);
        if (b % 2 == 0)
            return val * val % mod;
        else
            return val * val % mod * a % mod;
    }

}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public char NextChar()
        {
            try
            {
                return (char)inputStream.Read();
            }
            catch (IOException)
            {
                return '\0';
            }
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = (NextLine() + string.Empty).Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            var t = typeof(T);

            if (t == typeof(char))
                return (T)(object)NextChar();

            object s = NextString();

            if (t == typeof(string))
                return (T)s;

            return (T)Convert.ChangeType(s, typeof(T));
        }

        public IEnumerable<T> NextWhile<T>(Predicate<T> pred)
        {
            if (pred == null)
                yield break;

            T res = Next<T>();

            while (pred(res))
            {
                yield return res;

                res = Next<T>();
            }
        }

        public IEnumerable<T> NextSeq<T>(long n)
        {
            for (var i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "yes" : "no");
        }

        public void PrintLine(bool o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));
        }

        public void PrintLine<T>(T o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static void Each<T>(this IEnumerable<T> self, Action<T> action)
        {
            foreach (var v in self)
                action(v);
        }

        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<T> fval)
        {
            for (var i = 0; i < self.Count; i++)
                self[i] = fval();

            return self;
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            return self.Fill(() => val);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long> val = null)
        {
            return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long, long> val)
        {
            return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));
        }

        public static long HashOne<T>(this T self, long current)
        {
            return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));
        }

        public static IList<T1> BuildSegTree<T1, T2>(this IList<T2> a, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            var t = new T1[a.Count << 2];

            a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);

            return t;
        }

        private static void BuildSegTree<T1, T2>(this IList<T2> a, IList<T1> t, int v, int tl, int tr, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            if (tl == tr)
            {
                t[v] = convert(a[tl]);
            }
            else
            {
                int tm = (tl + tr) >> 1;

                BuildSegTree(a, t, v << 1, tl, tm, combine, convert);
                BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);

                t[v] = combine(t[v << 1], t[(v << 1) + 1]);
            }
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override bool Equals(object obj)
        {
            var co = obj as P<T1, T2>;

            return co != null && co.GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
            hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode());
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var a = io.NextLong();
            var b = io.NextLong();

            io.Print(Calc(b) - Calc(a-1));
        }

        private long Calc(long a)
        {
            var al = (long)Math.Log10(a) + 1;

            if (al == 1)
                return a;
            else
            {
                var dgts = new long[al];

                var xa = a;

                for (int i = 0; i < al; i++)
                {
                    dgts[al- i -1] = xa % 10;
                    xa = xa / 10;
                }

                long res = (long)Math.Pow(10, al - 2) * (dgts[0] - 1) + 9;

                for (int i = 2; i < al ; i++)
                    res += (long)Math.Pow(10, i - 2) * 9;

                if (al < 2)
                    res++;
                else
                    res += (a % (long)Math.Pow(10, al - 1))/10 + 1;

                if (dgts[0] > dgts[al - 1])
                    res--;

                return res;
            }
        }
    }

}


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

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {

            //Little Elephant and Interval

            var a = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt64);

            const long maxn = 1000000000000000000;

            long l = a[0], r = a[1];

            long low = 1, high = 9;

            long ans = 0, c = 9;

            //high

            while (high <= r && low < maxn)
            {

                ans += c;

                low *= 10;
                high = high * 10 + 9;

                if (low > 99)
                {

                    c *= 10;

                }

            }

            for (long i = low; i <= r; i++)
            {

                long x = (long)Math.Log10(1.0 * i);

                long first = i / (long)Math.Pow(10.0, 1.0 * x);
                long last = i % 10;

                if (first == last)
                {

                    ans++;

                }

            }

            //low

            low = 1;
            high = 9;

            c = 9;

            while (high <= l && low < maxn)
            {

                ans -= c;

                low *= 10;
                high = high * 10 + 9;

                if (low > 99)
                {

                    c *= 10;

                }

            }

            for (long i = low; i < l; i++)
            {

                long x = (long)Math.Log10(1.0 * i);

                long first = i / (long)Math.Pow(10.0, 1.0 * x);
                long last = i % 10;

                if (first == last)
                {

                    ans--;

                }

            }

            Console.WriteLine(ans);

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int[] arr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            int lvl = arr[0] + 1;
            int n = arr[1], ans = 0, total = 1, totallists = 0 ;
            double lists = Math.Pow(2, arr[0])/ 2, max = Math.Pow(2, arr[0]), min = 1;
            bool direction = true;
            for (int i = 1; i < lvl; i++) {
                totallists += (int)Math.Pow(2, i);
            }
                while (totallists != 0){
                    if (n <= lists && direction == false)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        max = lists;
                        lists = Math.Floor((max + min)/2);
                    }
                    else if (n <= lists && direction == true) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        max = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == true)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == false) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }

                }
                Console.WriteLine(total - 1);
                //Console.ReadKey();
        }
    }
}