using System;
namespace ConsoleApp2
{

    class Program
    {
        static void Main(string[] args)
        {
            String[] input1 = Console.ReadLine().Split();
            long K = Int32.Parse(input1[0]);
            long P = Int32.Parse(input1[1]);
            long result = 0;
            for (int k = 1; k <= K; ++k) {
                long temp = k;
                long N = k;
                while (temp > 0) {
                    long mod = temp % 10;
                    temp = temp / 10;
                    N = N * 10 + mod;
                }
                result += N % P;
            }
            result = result % P;
            Console.WriteLine(result);
        }
    }
}

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

namespace ktolli
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int k = Convert.ToInt32(s[0]);
            int p = Convert.ToInt32(s[1]);

            long sum = 0;
            for (int i = 1; i <= k;i++)
            {
                string palindrNum = i.ToString() + String.Join("",i.ToString().Reverse().ToArray());
                sum += Convert.ToInt64(palindrNum);
            }

            Console.Write(sum % p);
        }
    }
}

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

class Program
{
        static void Main(string[] args)
        {
                int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int k = input[0], p = input[1];
                int sum = 0;
                for (var i = 1; i <= k; ++i)
                {
                        var zcyi = ZcyAt(i);
                        sum = (sum + (int)(zcyi % p)) % p;
                }
                Console.WriteLine(sum);
        }

        static long ZcyAt(int i)
        {
                long zcyLeft = i;
                int zcyRight = 0;
                while (i > 0)
                {
                        zcyRight *= 10;
                        zcyRight += i % 10;
                        i /= 10;
                        zcyLeft *= 10;
                }
                return zcyLeft + zcyRight;
        }
}

using System;
using System.Collections.Generic;

namespace _897B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] InputStirng = Console.ReadLine().Split();
            long k = Convert.ToInt32(InputStirng[0]);
            long p = Convert.ToInt32(InputStirng[1]);

            long Sum = 0;
            for (int i = 1; i < k + 1; i++)
            {
                string Reverse = "";
                for (int j = 0; j < i.ToString().Length; j++) Reverse = i.ToString()[j] + Reverse;
                Sum += Convert.ToInt64(i.ToString() + Reverse);
            }

            Console.WriteLine(Sum % p);
        }
    }
}

using System;
using System.Linq;

namespace CSharp
{
    class _897B
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int k = int.Parse(tokens[0]);
            int p = int.Parse(tokens[1]);

            Console.WriteLine(Enumerable.Range(1, k).Select(i => long.Parse(new string(i.ToString().ToArray().Concat(i.ToString().Reverse()).ToArray())) % p).Sum() % p);
        }
    }
}

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

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int K, P;
    private void Scan()
    {
        var sc = new Scanner();
        K = sc.NextInt();
        P = sc.NextInt();
    }

    public void Solve()
    {
        Scan();
        long ans = 0;
        for(int i=1;i<=K;i++)
        {
            ans += Num(i);
            ans %= P;
        }
        Console.WriteLine(ans);
    }

    private long Num(int i)
    {
        long ret = i;
        while (i > 0)
        {
            ret *= 10;
            ret += i % 10;
            i /= 10;
            ret %= P;
        }
        return ret;
    }

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

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

namespace CFCSH
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] StrArr = Console.ReadLine().Split(' ');
            long k = long.Parse(StrArr[0]);
            long p = long.Parse(StrArr[1]);
            List<string> l = new List<string> { "00", "11", "22", "33", "44", "55", "66", "77", "88", "99" };
            ICollection<long> num = new HashSet<long> { 11, 22, 33, 44, 55, 66, 77, 88, 99 };

            int sz = 0;
            string sub;
            long temp;
            while (num.Count < 100010)
            {
                sz = l.Count;
                for (int j = 0; j <= 9; ++j)
                {
                    for (int i = 0; i < sz; ++i)
                    {
                        sub = j.ToString() + l[i] + j.ToString();
                        l.Add(sub);
                        if (j != 0)
                        {
                            temp = long.Parse(sub);
                            num.Add(temp);
                        }

                    }
                }
            }
            long sum = 0;
            int q = 0;
            foreach (long par in num)
            {
                if (q < k)
                    sum += par % p;
                else
                    break;
                ++q;
            }
            Console.WriteLine(sum % p);

        }

    }
}

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

namespace ярморка
{
    class Program
    {
        static string Reverse(string s)
        {
            string res = "";
            for (int i = 0; i < s.Length; i++)
            {
                res = s[i] + res;
            }

            return res;
        }
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split();
            int k = Convert.ToInt32(input[0]);
            UInt64 p = Convert.ToUInt64(input[1]);

            UInt64 sum = 0;

            for (int i = k; i >= 1; i--)
            {
                string s = Convert.ToString(i) + Reverse(Convert.ToString(i));

                sum += Convert.ToUInt64(s);
            }

            Console.WriteLine(sum % p);

        }
    }
}

using System;

public class Chtholly
{
    public static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int k = int.Parse(input[0]);
        long p = int.Parse(input[1]);

        long sum = 0;

        for (int i = 1; i <= k; i++)
        {
            string x = i.ToString();
            string zcy = x + Reverse(x);
            long zcy_number = long.Parse(zcy);
            sum += zcy_number;
        }

        Console.WriteLine(sum % p);
    }

    static string Reverse(string s)
    {
        char[] chars = s.ToCharArray();
        Array.Reverse(chars);
        return new string(chars);
    }
}

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

namespace ConsoleApp6
{
    class Program
    { static int nxt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;

        }
       static string rev(ulong a)
        {
            string h = Convert.ToString(a);
                string itog = "";
                for (int i = h.Length - 1; i >= 0; i--)
                {
                    itog += h[i];

                }
                return itog;

        }
        static void Main(string[] args)
        {
            string[] k = Console.ReadLine().Split();
            ulong n = Convert.ToUInt64(k[0]), m = Convert.ToUInt64(k[1]) , itog = 0;
            for(ulong i = 1; i <= n; i++)
            {
                ulong tp = i;
                string s = Convert.ToString(tp);
                s =s + rev(tp);
                itog += Convert.ToUInt64(s);
                itog %= m;

            }
            Console.WriteLine(itog%m);
        }
    }
}

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

namespace Codeforces
{
   class B
   {
      static void Main(string[] args)
      {
          string[] token = Console.ReadLine().Split();
          int k = int.Parse(token[0]);
          int p = int.Parse(token[1]);
          long sum = 0;

          for(int i=1;i<=k;i++){
             string ss = i.ToString();
             string sss = ss + Reverse(ss);
             long num = long.Parse(sss);
             sum+=num;
          }

          Console.WriteLine(sum%p);

      }

      public static string Reverse( string s )
      {
          char[] charArray = s.ToCharArray();
          Array.Reverse( charArray );
          return new string( charArray );
      }

   }

}

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

namespace dd
{
	class MainClass
	{
		public static long foo(long x)
		{
			List<long> digits = new List<long>();
			while (x > 0)
			{
				digits.Add(x % 10);
				x /= 10;
			}
			long sum = 0, pw = 1;
			digits.Reverse();
			foreach (long j in digits)
			{
				sum += j * pw;
				pw *= 10;
			}
			digits.Reverse();
			foreach (long j in digits)
			{
				sum += j* pw;
				pw *= 10;
			}
			return sum;
		}

		public static void Main(string[] args)
		{
			string [] values = Console.ReadLine().Split(' ');
			long N = long.Parse(values[0]);
			long MOD = long.Parse(values[1]);
			long ans = 0;
			for (int i = 1; i <= N; ++i)
			{
				ans += foo(i);
				ans %= MOD;
			}
			Console.WriteLine(ans);
		}
	}
}

using System;
using System.IO;
using System.Text;

namespace Chtholly_s_request
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static long Solve(string[] args)
        {
            int k = Next();
            int p = Next();

            long ans = 0;
            for (int i = 1; i <= k; i++)
            {
                long n = i;
                long ii = i;
                while (n > 0)
                {
                    ii = ii*10 + n%10;
                    n /= 10;
                }
                ans += ii;
            }

            return ans%p;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            var k = ReadLong();
            var p = ReadLong();
            var sum = 0L;

            for (int i = 1; i <= k; i++)
            {
                sum += long.Parse(i.ToString() + new string(i.ToString().Reverse().ToArray()));
                sum %= p;
            }
            return sum;
        }
        long fastpow(long b, long x)
        {
            checked
            {
                if (x == 0)
                    return 1;
                if (x == 1)
                    return b;
                if (x % 2 == 0)
                    return fastpow(b * b % commonMod, x / 2);
                return b * fastpow(b, x - 1) % commonMod;
            }
        }
        int nod(int a, int b)
        {
            if (a < b)
                return nod(b, a);
            if (b == 0)
                return a;
            return nod(b, a % b);
        }

        class End
        {
            public long Val { get; set; }
            public bool Left { get; set; }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10)
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            //var i = s.IndexOf(' ');
            //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }

}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;

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

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;
        private long k;
        private long p;
        private long answ;
        private int count;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            k = sr.NextInt64();
            p = sr.NextInt64();
            answ = 0L;
            count = 0;
            for (var i = 1; i <= k; i++) {
                Generate(i, 0, new char[i]);
                if (count == k)
                    break;
            }

            sw.WriteLine(answ);
        }

        private void Generate(int total, int curr, char[] val)
        {
            if (count == k)
                return;

            if (curr == total) {
                count++;
                var arg2 = Int64.Parse(new string(val) + new string(val.Reverse().ToArray()));
                answ = (answ % p + arg2 % p) % p;
                return;
            }

            for (var i = 0; i <= 9; i++) {
                if(i == 0 && curr == 0)
                    continue;
                val[curr] = (char) ('0' + i);
                Generate(total, curr + 1, val);
                if (count == k) {
                    break;
                }
            }
        }

        ~Task()
        {
            Dispose(false);
        }

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

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

class Graph
{
    private readonly List<int>[] edges;

    public Graph(int n)
    {
        edges = new List<int>[n];
    }

    public void Insert(int x, int y)
    {
        if (edges[x] == null) {
            edges[x] = new List<int>();
        }
        edges[x].Add(y);
    }

    public void Solution()
    {

    }

    private void DfsVisit(int v, bool[] visited)
    {
        visited[v] = true;
        if (edges[v] != null) {
            for (var i = 0; i < edges[v].Count; i++) {
                if (!visited[edges[v][i]]) {
                    DfsVisit(edges[v][i], visited);
                }
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    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(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

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

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    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.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public static bool IsPalindrome(BigInteger n)
        {
            BigInteger flip = 0;
            for (BigInteger i = n; i > 0; i /= 10)
            {
                flip = flip * 10 + (i % 10);
            }

            return n == flip;
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int k = input[0];
            int p = input[1];

            int sum = 0;

            for (int i = 1; i <= k; ++i)
            {
                long zcy = Palindrom(i);
                sum = (sum + (int)(zcy % p)) % p;
            }

            Console.WriteLine(sum);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        static long Palindrom(int i)
        {
            long zcyLeft = i;
            int zcyRight = 0;
            while (i > 0)
            {
                zcyRight *= 10;
                zcyRight += i % 10;
                i /= 10;
                zcyLeft *= 10;
            }
            return zcyLeft + zcyRight;
        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}

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

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      var k = input.ReadInt();
      var p = input.ReadLong();
      Console.Write(Zcy().Take(k).Sum() % p);
    }

    private static IEnumerable<long> Zcy()
    {
      for (int i = 1; ; i++)
      {
        var s = i.ToString();
        yield return long.Parse(s + string.Join("", s.Reverse()));
      }
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }

    #region Service functions

    private static int GCD(int a, int b)
    {
      while (b != 0)
      {
        a %= b;
        int t = b;
        b = a;
        a = t;
      }
      return a;
    }

    #endregion
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

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

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

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

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

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;

public class Test
{
	public static void Main()
	{
		string[] input1 = Console.ReadLine().Split(' ');
		Int64 k = int.Parse(input1[0]);
		Int64 p = int.Parse(input1[1]);

		Int64 sum = 0;

		for(Int64 x=1;x<=k;x++){
			string xx = x+""+Reverse(x+"");
			if((double)xx.Length/2 == (Int64)xx.Length/2 ){
				string r = Reverse(xx);
				if(r == xx){
					sum+=Int64.Parse(xx);
				}
			}
		}

		double output = sum % p;

		Console.WriteLine(output);
	}

	public static string Reverse(string s)
	{
		char[] charArray = s.ToCharArray();
		Array.Reverse( charArray );
		return new string( charArray );
	}
}

using System;
using System.IO;

namespace MindCrack
{

	class MindCrack
	{
		public static void Main()
		{
		    //input
		    string inputStr = Console.ReadLine();
		    string[] input = inputStr.Split(' ');
		    int k, p;
		    k = int.Parse(input[0]);
			p = int.Parse(input[1]);

			//calculations
			long result;
			long summ = 0;
			for(int i = 1; i <= k; i++)
			{
			    string temp = i.ToString();
			    string revtemp = "";
			    for(int j = 0; j < temp.Length; j++)
			    {
			        revtemp += temp[temp.Length-1-j];
			    }
			    summ += long.Parse(temp + revtemp);
			}
			result = summ%p;

			//output
			Console.Write(result);
		}
	}

}

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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;

        long ans = 0;
        long p;
        int k;

        long MakePali(int i)
        {
            int numDigits = 0;
            long powTen = 1;

            long rez = i;
            long pali = 0;

            while(i>0)
            {
                numDigits++;
                powTen *= 10;
                var lastDig = i % 10;
                pali *= 10;
                pali += lastDig;
                i /= 10;
            }

            rez *= powTen;
            rez += pali;

            return rez;
        }

        public void Solve()
        {
            k = ioHelper.ReadNextInt();
            p = ioHelper.ReadNextInt();

            for(int i=1;i<=k;i++)
            {
                var val = MakePali(i);
                val %= p;
                ans += val;
                ans %= p;
            }

            ioHelper.WriteLine(ans.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

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

namespace Codeforces.NET
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] parts = line.Split(' ').ToArray();
            long k = int.Parse(parts[0]);
            long p = int.Parse(parts[1]);
            long nr = 1;
            long sol = 0;
            for (int i = 1; i<=k; i++)
            {
                long nrAux = nr;
                long aux = nr;
                while (aux != 0)
                {
                    nrAux = nrAux * 10 + aux % 10;
                    aux = aux / 10;
                }

                sol = (sol + nrAux) % p;
                nr++;
            }

            Console.WriteLine(sol);
            Console.ReadLine();
        }
    }
}

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

namespace ConsoleApplication36
{
    class Program
    {
        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }
        static void Main(string[] args)
        {
            long n, m , ans=0 , val=0;
            string s, rev;
            string[] values = Console.ReadLine().Split(' ');
            n = int.Parse(values[0]);
            m = int.Parse(values[1]);
            for (int i = 1 ; i <= n; i++)
            {
                s = i.ToString();
                s += Reverse(s);
                if (long.TryParse(s, out val))
                    ans += val;
            }
            Console.WriteLine(ans%m);
        }
    }
}

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

class Startup
{
    static void Main()
    {
        List<BigInteger> inputList = ReadLineAndParseToList();
        BigInteger k = inputList[0];
        BigInteger p = inputList[1];
        BigInteger sumOfK = 0;

        for (BigInteger i = 1; i <= k; i++)
        {
            sumOfK += ReverseAndMake(i);
        }

        Console.WriteLine(sumOfK%p);
    }

    public static BigInteger ReverseAndMake(BigInteger intS)
    {
        string s = intS.ToString();
        char[] charArray = s.ToCharArray();
        Array.Reverse(charArray);
        return BigInteger.Parse(s + new string(charArray));
    }

    public static List<BigInteger> ReadLineAndParseToList()
    {
        return Console.ReadLine().Split().Select(BigInteger.Parse).ToList();
    }

}

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

namespace Codeforces.NET
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] parts = line.Split(' ').ToArray();
            int k = int.Parse(parts[0]);
            int p = int.Parse(parts[1]);
            int nr = 1;
            int sol = 0;
            for (int i = 1; i<=k; i++)
            {
                int nrAux = nr;
                int aux = nr;
                while (aux != 0)
                {
                    nrAux = nrAux * 10 + aux % 10;
                    aux = aux / 10;
                }

                sol = (sol + nrAux) % p;
                nr++;
            }

            Console.WriteLine(sol);
            Console.ReadLine();
        }
    }
}

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

namespace ConsoleApplication36
{
    class Program
    {
        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }
        static void Main(string[] args)
        {
            int n, m , ans=0 , val=0;
            string s, rev;
            string[] values = Console.ReadLine().Split(' ');
            n = int.Parse(values[0]);
            m = int.Parse(values[1]);
            for (int i = 1 ; i <= n; i++)
            {
                s = i.ToString();
                s += Reverse(s);
                if (int.TryParse(s, out val))
                    ans += val;
            }
            Console.WriteLine(ans%m);
        }
    }
}

using System;
using System.Linq;
namespace ConsoleApp2
{

    class Program
    {
        static void Main(string[] args)
        {
            String[] input1 = Console.ReadLine().Split();
            int K = Int32.Parse(input1[0]);
            int P = Int32.Parse(input1[1]);
            long result = 0;
            for (int k = 1; k <= K; ++k) {
                int temp = k;
                int N = k;
                while (temp > 0) {
                    int mod = temp % 10;
                    temp = temp / 10;
                    N = N * 10 + mod;
                }
                result += N % P;
            }
            result = result % P;
            Console.WriteLine(result);
        }
    }
}

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

class Program
{
        static int _mod;
        static void Main(string[] args)
        {
                int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int k = input[0], p = input[1];
                _mod = p;

                var q = new Queue<int>();
                Array.ForEach(new[] { 0, 11, 22, 33, 44, 55, 66, 77, 88, 99 }, q.Enqueue);
                int sum = 0;
                int shiftPow = 3;
                while (k-- > 0)
                {
                        int el = q.Dequeue();
                        if (el == 0)
                                ++k;
                        sum = Add(sum, el);
                        if (el % 10 == 9)
                                shiftPow += 2;
                        q.Enqueue(Add(el, Add(Pow(10, shiftPow), 1)));

                }

                Console.WriteLine(sum);
        }

        static int Add(int n1, int n2)
        {
                long ln1 = n1;
                return (int)((ln1 + n2) % _mod);
        }

        static int Pow(int n, int pow)
        {
                long res = 1;
                long ln = n % _mod;
                while (pow > 0)
                {
                        if ((pow & 1) == 1)
                                res = (res * ln) % _mod;
                        pow >>= 1;
                        ln = (ln * ln) % _mod;
                }
                return (int)res;
        }
}

using System;

public class Test
{
	public static void Main()
	{
		string[] input1 = Console.ReadLine().Split(' ');
		Int64 k = int.Parse(input1[0]);
		Int64 p = int.Parse(input1[1]);

		Int64 sum = 0;

		for(Int64 x=1;x<=k;x++){
			string xx = x+""+x;
			if((float)xx.Length/2 == (Int64)xx.Length/2){
				if(Reverse(xx) == xx){
					sum+=Int64.Parse(xx);
				}
			}
		}

		double output = sum % p;

		Console.WriteLine(output);
	}

	public static string Reverse(string s)
	{
		char[] charArray = s.ToCharArray();
		Array.Reverse( charArray );
		return new string( charArray );
	}
}

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

namespace CFCSH
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] StrArr = Console.ReadLine().Split(' ');
            long k = long.Parse(StrArr[0]);
            long p = long.Parse(StrArr[1]);
            List<string> l = new List<string> { "00", "11", "22", "33", "44", "55", "66", "77", "88", "99" };
            List<long> num = new List<long> { 11, 22, 33, 44, 55, 66, 77, 88, 99 };
            int sz = 0;
            string sub;
            long temp;
            while (num.Count < 100010)
            {
                sz = l.Count;
                for (int j = 0; j <= 9; ++j)
                {
                    for (int i = 0; i < sz; ++i)
                    {
                        sub = j.ToString() + l[i] + j.ToString();
                        l.Add(sub);
                        if (j != 0)
                        {
                            temp = long.Parse(sub);
                            num.Add(temp);
                        }

                    }
                }
            }
            num.Sort();
            long sum = 0;
            for (int i = 0; i < k; ++i)
            {
                sum += num[i] % p;
            }
            Console.WriteLine(sum % p);

        }

    }
}

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

namespace CFCSH
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] StrArr = Console.ReadLine().Split(' ');
            long k = long.Parse(StrArr[0]);
            long p = long.Parse(StrArr[1]);
            List<string> l = new List<string> { "00", "11", "22", "33", "44", "55", "66", "77", "88", "99" };
            List<long> num = new List<long> { 11, 22, 33, 44, 55, 66, 77, 88, 99 };
            int sz = 0;
            string sub;
            long temp;
            while (num.Count < k)
            {
                sz = l.Count;
                for (int j = 0; j <= 9; ++j)
                {
                    for (int i = 0; i < sz; ++i)
                    {
                        sub = j.ToString() + l[i] + j.ToString();
                        l.Add(sub);
                        if (j != 0)
                        {
                            temp = long.Parse(sub);
                            num.Add(temp);
                        }

                    }
                }
            }
            num.Sort();
            long sum = 0;
            for (int i = 0; i < k; ++i)
            {
                sum += num[i] % p;
            }
            Console.WriteLine(sum % p);

        }

    }
}

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

namespace CFCSH
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] StrArr = Console.ReadLine().Split(' ');
            long k = long.Parse(StrArr[0]);
            long p = long.Parse(StrArr[1]);
            List<string> l = new List<string> { "00" , "11" , "22" , "33" , "44" , "55" , "66" , "77" , "88" , "99"};
            List<long> num = new List<long> { 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 };
            int sz = 0;
            int rem = 1;
            string sub;
            long temp;
            while (num.Count < k)
            {
                sz = l.Count;
                for (int i = 0; i < sz; ++i)
                {
                    for (int j = 0; j <= 9; ++j)
                    {
                       sub = j.ToString() + l[i] + j.ToString();
                        l.Add(sub);
                        if (j != 0)
                        {
                            temp = long.Parse(sub);
                            num.Add(temp);
                        }

                    }
                }
            }
            num.Sort();
            long sum = 0;
            for (int i = 0; i < k ; ++i)
            {
                sum += num[i] % p;
            }
            Console.WriteLine(sum % p);

        }

    }
}

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

namespace Codeforces
{
   class B
   {
      static void Main(string[] args)
      {
          string[] token = Console.ReadLine().Split();
          int k = int.Parse(token[0]);
          int p = int.Parse(token[1]);
          long sum = 0;

          int[] a = new int[4]{0,1,1,0};

          for(int i=0;i<Math.Min(10000,k);i++){
            string temp = a[0]+""+a[1]+""+a[2]+""+a[3];
            sum = (i<10)?sum + int.Parse(temp)/10:sum+int.Parse(temp);
            a[1]++;
            a[2]++;
            if(a[1]==10){
              a[1] = 0;
              a[2] = 0;
              a[0]++;
              a[3]++;
            }
          }

          Console.WriteLine(sum%p);

      }
   }

}


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;

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)
        {
            PrintLine(o ? "YES" : "NO");
        }

        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 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 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 n = io.NextInt();
            var m = io.NextInt();

            var x = io.NextInt();
            var y = io.NextInt();
            x = Math.Abs(x - io.NextInt());
            y = Math.Abs(y - io.NextInt());

            var res = (x > 4 || y > 4) || (x + y > 6);

            io.PrintLine(res ? "Second" : "First");
        }
    }

}

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

namespace AlgoTraining.Codeforces.C_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public string NextToken()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return _line[_iterator++];
        }
        public int NextInt()
        {
            return Convert.ToInt32(NextToken());
        }
        public long NextLong()
        {
            return Convert.ToInt64(NextToken());
        }
        public float NextFloat()
        {
            return float.Parse(NextToken());
        }
        public double NextDouble()
        {
            return Convert.ToDouble(NextToken());
        }
    }
    class PlayingWithSuperglueCroc
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), m = fs.NextInt();
                int x1 = fs.NextInt(), y1 = fs.NextInt();
                int x2 = fs.NextInt(), y2 = fs.NextInt();
                int w = Math.Abs(x1 - x2) + 1, h = Math.Abs(y1 - y2) + 1;
                if ((w == 5 && h == 5) || (w >= 6 || h >= 6) || (w == 4 && h == 5) || (w == 5 && h == 4)) writer.WriteLine("Second");
                else writer.WriteLine("First");
            }
        }
    }
}


using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var c = ReadLine().Split();
        var n = int.Parse(c[0]);
        var x = decimal.Parse(c[1]);
        var list = new List<decimal>();
        list.Add(x);
        var res = 0;
        while (true)
        {
            var next = new List<decimal>();
            foreach (var li in list)
            {
                var str = li.ToString();
                if (str.Length == n)
                {
                    WriteLine(res);
                    return;
                }
                for (var i = '2'; i <= '9'; ++i) if (str.Contains(i))
                {
                    next.Add(li * (i - '0'));
                }
            }
            if (next.Count == 0)
            {
                WriteLine(-1);
                return;
            }
            var max = next.Max();
            if (next.Count > 10000)
            {
                next.Sort();
                next = next.Skip(next.Count - 10000).ToList();
            }
            list = next;
            ++res;
        }
    }
}

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

namespace Compete2
{
    partial class MainClass
    {
        public static void Main(string[] args)
        {
            int count = 1; //int.Parse(Console.ReadLine());
            List<string> output = new List<string>();

            for (int z = 0; z < count; z++)
            {
                //Console.ReadLine();
                //var s = Console.ReadLine();
                //var n = int.Parse(Console.ReadLine());
                var a = Console.ReadLine().Split(' ').Select(qw => ulong.Parse(qw)).ToList();
                //var b = Console.ReadLine().Split(' ').Select(qw => long.Parse(qw)).ToList();
                //var c = Console.ReadLine().Split(' ').Select(qw => long.Parse(qw)).ToList();
                //var b = long.Parse(Console.ReadLin    e());

                ulong o = ulong.MaxValue;
                //bool can = true;

                SortedSet<ulong> visited = new SortedSet<ulong>();

                Queue<ulong[]> q = new Queue<ulong[]>();

                if ((ulong)a[1].ToString().Length >= a[0])
                    o = 0;
                else
                    q.Enqueue(new ulong[] { a[1], 0 });

                while (q.Count>0)
                {
                    var x = q.Dequeue();

                    if (x[1] + 1 >= o)
                        continue;

                    var ds = x[0].ToString().Distinct().Select(i=>int.Parse(i.ToString())).OrderByDescending(i=>i).ToList();

                    if (ds.Contains(1))
                        ds.Remove(1);

                    if (ds.Contains(0))
                        ds.Remove(0);

                    BigInteger bi = x[0];

                    for (int i = 0; i < ds.Count; i++)
                    {
                        BigInteger bi2 = bi * ds[i];

                        if ((ulong)bi2.ToString().Length >= a[0])
                        {
                            if (x[1] + 1 < o)
                                o = x[1] + 1;
                        }
                        else
                        {
                            var u = (ulong)bi2;
                            if (!visited.Contains(u))
                            {
                                q.Enqueue(new ulong[] { u, x[1] + 1 });
                                visited.Add(u);
                            }
                        }
                    }
                }

                if (o == ulong.MaxValue)
                    output.Add("-1");
                else
                output.Add(o.ToString());
                //output.Add(string.Join(" ", o));
                /*if (can)
                    output.Add("Yes");
                else
                    output.Add("No");*/
            }

            output.ForEach(d => Console.WriteLine(d));
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BI = System.Numerics.BigInteger;

namespace ProblemD {
	internal class TEST {
		public static void Main() {
			Sol mySol = new Sol();
			mySol.Solve();
		}
	}

	internal class Sol {
		public void Solve() {

			var hs = new HashSet<BI>();
			hs.Add(X);
			for(int t=0; ; t++) {
				if(hs.Count == 0) {
					Console.WriteLine(-1);
					return;
				}
				var nhs = new HashSet<BI>();
				foreach(var n in hs) {

					var x = n;
					int len = 0;
					int[] cnt = new int[10];
					while (x > 0) {
						cnt[(int)(x % 10)]++;
						len++;
						x /= 10;
					}
					for(int i = 2; i <= 9; i++) {
						if (cnt[i] == 0) continue;
						BI nn = n * i;
						if(nn.ToString().Length == N) {
							Console.WriteLine(t + 1);
							return;
						}
						nhs.Add(nn);
					}
				}
				hs = nhs;
			}

		}
		int N;
		long X;
		public Sol() {
			var d = rla();
			N = (int)d[0]; X = d[1];
		}

		static String rs() { return Console.ReadLine(); }
		static int ri() { return int.Parse(Console.ReadLine()); }
		static long rl() { return long.Parse(Console.ReadLine()); }
		static double rd() { return double.Parse(Console.ReadLine()); }
		static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
		static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
		static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
		static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
		static T[] mka<T>(int n, T ini) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = ini; return ret; }
		static T[][] mka2<T>(int n, int m, T ini) { T[][] ret = new T[n][]; for (int i = 0; i < n; i++) ret[i] = mka(m, ini); return ret; }
		static T[][][] mka3<T>(int n, int m, int l, T ini) { T[][][] ret = new T[n][][]; for (int i = 0; i < n; i++) ret[i] = mka2(m, l, ini); return ret; }
		static T[][][][] mka4<T>(int n, int m, int l, int k, T ini) { T[][][][] ret = new T[n][][][]; for (int i = 0; i < n; i++) ret[i] = mka3(m, l, k, ini); return ret; }
	}

}

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

namespace olymp_codeforces
{
    class Program
    {
        void dashla(long x, out HashSet<long> digits, out int cnt)
        {
            digits = new HashSet<long>();
            cnt = 0;
            while(x > 0)
            {
                digits.Add(x % 10);
                cnt++;
                x = x/10;
            }
        }
        int res = int.MaxValue;
        Dictionary<long, int> svlebi = new Dictionary<long, int>();
        void rec(long x, int n, int svla)
        {
            if (svlebi.ContainsKey(x) && svlebi[x] <= svla)
                return;
            svlebi[x] = svla;
            HashSet<long> digits;
            int cnt;
            dashla(x, out digits, out cnt);
            if(cnt == n)
            {
                res = Math.Min(res, svla);
                return;
            }
            if (svla >= res || svla > n+ 2)
                return;

            var dSorted = digits.ToList().OrderByDescending(i => i).ToList(); //   digits.OrderBy(_ => rand.Next()).ToList();
            //dSorted.Sort();
            for (int i = 0; i < dSorted.Count; i++)
            {
                long digit = dSorted[i];
                if (digit < 2)
                    break;
                rec(x * digit, n, svla + 1);
            }
        }

        public  void Solve()
        {
            // var t = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
            long n = input[0], x = input[1];
            rec(x, (int)n, 0);
            if (res < int.MaxValue)
                Console.WriteLine(res);
            else
                Console.WriteLine(-1);
        }

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

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BI = System.Numerics.BigInteger;

namespace ProblemD {
	internal class TEST {
		public static void Main() {
			Sol mySol = new Sol();
			mySol.Solve();
		}
	}

	internal class Sol {
		public void Solve() {

			var hs = new HashSet<BI>();
			hs.Add(X);
			for(int t=0; ; t++) {
				if(hs.Count == 0) {
					Console.WriteLine(-1);
					return;
				}
				var nhs = new HashSet<BI>();
				foreach(var n in hs) {

					var x = n;
					int len = 0;
					int[] cnt = new int[10];
					while (x > 0) {
						cnt[(int)(x % 10)]++;
						len++;
						x /= 10;
					}
					for(int i = 2; i <= 9; i++) {
						if (cnt[i] != 1) continue;
						BI nn = n * i;
						if(nn.ToString().Length == N) {
							Console.WriteLine(t + 1);
							return;
						}
						nhs.Add(nn);
					}
				}
				hs = nhs;
			}

		}
		int N;
		long X;
		public Sol() {
			var d = rla();
			N = (int)d[0]; X = d[1];
		}

		static String rs() { return Console.ReadLine(); }
		static int ri() { return int.Parse(Console.ReadLine()); }
		static long rl() { return long.Parse(Console.ReadLine()); }
		static double rd() { return double.Parse(Console.ReadLine()); }
		static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
		static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
		static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
		static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
		static T[] mka<T>(int n, T ini) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = ini; return ret; }
		static T[][] mka2<T>(int n, int m, T ini) { T[][] ret = new T[n][]; for (int i = 0; i < n; i++) ret[i] = mka(m, ini); return ret; }
		static T[][][] mka3<T>(int n, int m, int l, T ini) { T[][][] ret = new T[n][][]; for (int i = 0; i < n; i++) ret[i] = mka2(m, l, ini); return ret; }
		static T[][][][] mka4<T>(int n, int m, int l, int k, T ini) { T[][][][] ret = new T[n][][][]; for (int i = 0; i < n; i++) ret[i] = mka3(m, l, k, ini); return ret; }
	}

}

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

namespace ProblemD {
	internal class TEST {
		public static void Main() {
			Sol mySol = new Sol();
			mySol.Solve();
		}
	}

	internal class Sol {
		public void Solve() {

			var hs = new HashSet<long>();
			hs.Add(X);
			for(int t=0; ; t++) {
				if(hs.Count == 0) {
					Console.WriteLine(-1);
					return;
				}
				var nhs = new HashSet<long>();
				foreach(var n in hs) {

					var x = n;
					int len = 0;
					int[] cnt = new int[10];
					while (x > 0) {
						cnt[x % 10]++;
						len++;
						x /= 10;
					}
					for(int i = 2; i <= 9; i++) {
						if (cnt[i] != 1) continue;
						long nn = n * i;
						if(nn.ToString().Length == N) {
							Console.WriteLine(t + 1);
							return;
						}
						nhs.Add(nn);
					}
				}
				hs = nhs;
			}

		}
		int N;
		long X;
		public Sol() {
			var d = rla();
			N = (int)d[0]; X = d[1];
		}

		static String rs() { return Console.ReadLine(); }
		static int ri() { return int.Parse(Console.ReadLine()); }
		static long rl() { return long.Parse(Console.ReadLine()); }
		static double rd() { return double.Parse(Console.ReadLine()); }
		static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
		static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
		static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
		static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
		static T[] mka<T>(int n, T ini) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = ini; return ret; }
		static T[][] mka2<T>(int n, int m, T ini) { T[][] ret = new T[n][]; for (int i = 0; i < n; i++) ret[i] = mka(m, ini); return ret; }
		static T[][][] mka3<T>(int n, int m, int l, T ini) { T[][][] ret = new T[n][][]; for (int i = 0; i < n; i++) ret[i] = mka2(m, l, ini); return ret; }
		static T[][][][] mka4<T>(int n, int m, int l, int k, T ini) { T[][][][] ret = new T[n][][][]; for (int i = 0; i < n; i++) ret[i] = mka3(m, l, k, ini); return ret; }
	}

}

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var c = ReadLine().Split();
        var n = int.Parse(c[0]);
        var x = decimal.Parse(c[1]);
        var list = new List<decimal>();
        list.Add(x);
        var res = 0;
        while (true)
        {
            var maxes = new decimal[10];
            foreach (var li in list)
            {
                var str = li.ToString();
                if (str.Length == n)
                {
                    WriteLine(res);
                    return;
                }
                for (var i = '2'; i <= '9'; ++i) if (str.Contains(i))
                {
                    var next = li * (i - '0');
                    var nstr = next.ToString();
                    for (var j = '2'; j <= '9'; ++j)
                    {
                        if (nstr.Contains(j))
                        {
                            maxes[j - '0'] = Math.Max(maxes[j - '0'], next);
                        }
                    }
                }
            }
            list = maxes.Where(m => m > 0).ToList();
            if (list.Count == 0)
            {
                WriteLine(-1);
                return;
            }
            ++res;
        }
    }
}