— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!


-----Input-----

The first line contains two integers k and p (1 ≤ k ≤ 10^5, 1 ≤ p ≤ 10^9).


-----Output-----

Output single integer — answer to the problem.


-----Examples-----
Input
2 100

Output
33

Input
5 30

Output
15



-----Note-----

In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

In the second example, $(11 + 22 + 33 + 44 + 55) \operatorname{mod} 30 = 15$.

Source: codeforces | Difficulty: EASY
Tags: Complete search


Solutions:
(n, m) = map(int, input().split())
sm = 0
for i in range(1, n + 1):
	s = str(i)
	sm += int(s + s[::-1])
print(sm % m)


temp = input()
k = int(temp.split()[0])
p = int(temp.split()[1])
total = 0
for i in range(k + 1):
	list1 = list(str(i))
	list2 = list1[:]
	list1.reverse()
	list3 = list2 + list1
	s = int(''.join(list3))
	total += s
print(total % p)


(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	a = str(i)
	a += a[::-1]
	ans += int(a)
	if ans >= p:
		i = ans // p
		ans = ans - i * p
print(ans)


(n, m) = map(int, input().split())
sum = 0
for i in range(n):
	sum += int(str(i + 1) + str(i + 1)[::-1])
print(sum % m)


import math
A = input().split()
k = int(A[0])
p = int(A[1])
palin = [0] * k
for i in range(0, k):
	digit = int(math.log(i + 1) // math.log(10))
	L = list(str(i + 1))
	M = L[::-1]
	fin = L + M
	num = ''.join(fin)
	palin[i] = int(num)
sum = 0
for i in range(0, k):
	sum = (sum + palin[i]) % p
print(sum)


(k, p) = input().split()
p = int(p)
ans = 0
for i in range(1, int(k) + 1):
	nr = str(i) + str(i)[::-1]
	ans += int(nr)
	ans %= p
print(ans)


lf = [11, 22, 33, 44, 55, 66, 77, 88, 99]
for i in range(1, 5):
	lili = [int(str(i) + str(i)[::-1]) for i in range(10 ** i, 10 ** (i + 1))]
	lf += lili
lf += [10000000001]
(a, b) = input().split()
a = int(a)
b = int(b)
print(sum(lf[:a]) % b)


(k, p) = map(int, input().split())
(c, s, i) = (0, 0, 1)
while c < k:
	s += int(str(i) + str(i)[::-1]) % p
	i += 1
	c += 1
print(s % p)


(k, p) = [int(i) for i in input().split()]
t = 0
for i in range(k):
	s = str(i + 1)
	s += s[::-1]
	t += int(s)
print(t % p)


(k, p) = map(int, input().split())
sum = 0
i = 1
while k:
	k -= 1
	s = str(i)
	tmp = int(s + s[::-1])
	sum += tmp
	i += 1
print(sum % p)


(k, p) = map(int, input().split())
s = 0
for i in range(1, k + 1):
	n = int(str(i) + str(i)[::-1])
	s = (s + n) % p
print(s)


(k, p) = map(int, input().split())
nums = [[] for i in range(10)]
current = []

def form(n, currentindex=0):
	if currentindex == n:
		res = ''.join(current)
		res += res[::-1]
		res = int(res)
		nums[n].append(res)
		return
	startnum = 0
	if currentindex == 0:
		startnum = 1
	for i in range(startnum, 10):
		current.append(str(i))
		form(n, currentindex + 1)
		current.pop()
for i in range(1, 6):
	form(i)
alll = []
for i in range(1, 6):
	alll.extend(nums[i])
alll.append(100000000001)
print(sum(alll[:k]) % p)


(a, b) = map(int, input().split(' '))
hlf = '1'
sum = 0
for i in range(a):
	cur = hlf + hlf[::-1]
	sum += int(cur)
	hlf = str(int(hlf) + 1)
print(sum % b)


def func(k):
	res = k
	lenn = len(k)
	for i in reversed(range(0, lenn)):
		res += k[i]
	return res
k = input()
k = k.split()
k1 = int(k[0])
p = int(k[1])
ans = 0
for i in range(1, k1 + 1):
	z2 = str(i)
	p2 = int(func(z2))
	ans += p2
print(ans % p)


(k, p) = map(int, input().split())

def zcy(n):
	ans = str(n) + str(n)[::-1]
	return int(ans)
ans = 0
for i in range(1, k + 1):
	ans = (ans + zcy(i)) % p
print(ans)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
l = []
ct = 0
for i in range(1, 10 ** 5 + 1):
	s = str(i)
	l.append(s + s[::-1])
(n, k) = map(int, input().split())
ans = 0
for i in range(n):
	ans += int(l[i])
	ans %= k
print(ans)


(k, p) = map(int, input().split())
s = 0
n = 0
l = []
for i in range(1, 10 ** 6):
	a = str(i)
	b = a[::-1]
	c = a + b
	l.append(c)
	if len(l) > k:
		break
for j in range(k):
	s += int(l[j])
print(s % p)


a = [int(x) for x in input().split()]
k = a[0]
p = a[1]
count = 0
for i in range(1, k + 1):
	x = str(i)
	z = x[::-1]
	y = int(x + z)
	count = count + y
print(count % p)


(k, p) = map(int, input().split())
x = []
for i in range(k + 1):
	x.append(int(str(i) + str(i)[::-1]))
print(sum(x) % p)


def calc(k, p):
	count = 0
	n = 1
	ans = 0
	while count < k:
		s = str(n)
		s2 = s + s[::-1]
		s3 = int(s2)
		ans = (ans % p + s3 % p) % p
		n += 1
		count += 1
	print(ans)
(k, p) = map(int, input().split())
calc(k, p)


s = list(map(int, input().split()))
k = s[0]
p = s[1]
ans = 0
for i in range(1, k + 1):
	m = str(i)
	a = int((m + m[::-1]).strip('0'))
	ans = (ans % p + a % p) % p
print(ans)


n = str(input(''))
aux = n.split(' ')
k = int(aux[0])
p = int(aux[1])
cont = 0
for i in range(k):
	izq = str(i + 1)
	der = izq[::-1]
	res = int(izq + der)
	cont += res
print(cont % p)


def main():
	inp = input()
	sum = 0
	no1 = int(inp.split()[0])
	no2 = int(inp.split()[1])
	for i in range(1, no1 + 1):
		sum += int(str(i) + str(i)[::-1]) % no2
	sum = sum % no2
	print(sum)
main()


def palgen():
	i = 1
	while True:
		ii = 10 * i
		r = range(i, ii)
		for j in r:
			s = str(j)
			yield (s + s[-2::-1])
		for j in r:
			s = str(j)
			yield (s + s[::-1])
		i = ii

def main():
	(k, p) = map(int, input().split())
	ans = 0
	cnt = 0
	for num in palgen():
		if len(num) % 2 == 0:
			for j in range(len(num)):
				if num[j] != num[-j - 1]:
					break
			else:
				ans = (ans + int(num) % p) % p
				cnt += 1
				if cnt == k:
					break
	print(ans)
main()


zcy = []
for i in range(1, 10 ** 5 + 1):
	zcy += [int(str(i) + str(i)[::-1])]
zcy = sorted(zcy)
(k, p) = map(int, input().split())
print(sum(zcy[:k]) % p)


import math
info = input()
info = info.split()
k = int(info[0])
p = int(info[1])

def palin(x):
	L = list(str(x))
	L.reverse()
	xR = ''.join(L)
	return int(str(x) + xR)
sumcon = 0
for j in range(1, k + 1):
	sumcon = sumcon + palin(j)
print(sumcon % p)


def zcy(n):
	s = str(n)
	return int(s + ''.join(reversed(s)))
(k, p) = [int(i) for i in input().split()]
print(sum((zcy(i) for i in range(1, k + 1))) % p)


def rewrite(string):
	return string[-1:-len(string) - 1:-1]
(k, p) = map(int, input().split())
i = 11
s = 0
for i in range(1, k + 1):
	c = str(i)
	s += int(c + rewrite(c))
print(s % p)


import math as mt
import sys
import string
from collections import Counter, defaultdict

def I():
	return int(input())

def M():
	return map(int, input().split())

def ARR():
	return list(map(int, input().split()))

def rev(s):
	rev_s = ''
	for elm in s:
		rev_s = elm + rev_s
	return rev_s

def main():
	(k, p) = M()
	ans = 0
	for i in range(1, k + 1):
		a = str(i)
		b = rev(a)
		a += b
		ans = (ans + int(a)) % p
	print(ans)
tc = 1
for _ in range(tc):
	main()


def add_to_zcy_list(start, end):
	zcy_upd = []
	for i in range(start, end + 1):
		s = str(i)
		zcy_upd.append(int(s + s[::-1]))
	return zcy_upd
(k, p) = (int(x) for x in input().split(' '))
zcy = add_to_zcy_list(1, 9) + add_to_zcy_list(10, 99) + add_to_zcy_list(100, 999) + add_to_zcy_list(1000, 9999) + add_to_zcy_list(10000, 99999) + [10000000001]
print(sum(zcy[:k]) % p)


(k, mod) = map(int, input().split())
val = 0
for i in range(1, k + 1):
	val = (val % mod + int(str(i) + str(i)[::-1]) % mod) % mod
	i += 1
print(val)


import math
(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	j = 1
	while j <= i:
		j *= 10
	first_half = i * j % p
	first_half_co = i
	second_half = 0
	while first_half_co > 0:
		digit = first_half_co % 10
		second_half = second_half * 10 + digit
		first_half_co = math.floor(first_half_co / 10)
	num = (first_half + second_half) % p
	ans = (ans + num) % p
print(ans)


(k, p) = [int(x) for x in input().split()]
found = 0
numb = 1
summa = 0
while found < k:
	temp = str(numb)
	dum = int(temp + ''.join(reversed(temp)))
	summa += dum
	found += 1
	numb += 1
print(summa % p)


arr = [11, 22, 33, 44, 55, 66, 77, 88, 99]
a = ['1', '0', '0', '1']
while a[0] != ':':
	for i in range(10):
		arr.append(int(''.join(a)))
		a[2] = chr(ord(a[2]) + 1)
		a[1] = chr(ord(a[1]) + 1)
	a[0] = chr(ord(a[0]) + 1)
	a[3] = chr(ord(a[3]) + 1)
	a[2] = '0'
	a[1] = '0'
a = ['1', '0', '0', '0', '0', '1']
while a[0] != ':':
	while a[1] != ':':
		for i in range(10):
			arr.append(int(''.join(a)))
			a[2] = chr(ord(a[2]) + 1)
			a[3] = chr(ord(a[3]) + 1)
		a[1] = chr(ord(a[1]) + 1)
		a[4] = chr(ord(a[4]) + 1)
		a[3] = '0'
		a[2] = '0'
	a[0] = chr(ord(a[0]) + 1)
	a[5] = chr(ord(a[5]) + 1)
	a[1] = '0'
	a[2] = '0'
	a[3] = '0'
	a[4] = '0'
a = ['1', '0', '0', '0', '0', '0', '0', '1']
while a[0] != ':':
	while a[1] != ':':
		while a[2] != ':':
			for i in range(10):
				arr.append(int(''.join(a)))
				a[3] = chr(ord(a[3]) + 1)
				a[4] = chr(ord(a[4]) + 1)
			a[2] = chr(ord(a[2]) + 1)
			a[5] = chr(ord(a[5]) + 1)
			a[4] = '0'
			a[3] = '0'
		a[1] = chr(ord(a[1]) + 1)
		a[6] = chr(ord(a[6]) + 1)
		a[2] = '0'
		a[3] = '0'
		a[4] = '0'
		a[5] = '0'
	a[0] = chr(ord(a[0]) + 1)
	a[7] = chr(ord(a[7]) + 1)
	a[1] = '0'
	a[2] = '0'
	a[3] = '0'
	a[4] = '0'
	a[5] = '0'
	a[6] = '0'
a = ['1', '0', '0', '0', '0', '0', '0', '0', '0', '1']
while a[0] != ':':
	while a[1] != ':':
		while a[2] != ':':
			while a[3] != ':':
				for i in range(10):
					arr.append(int(''.join(a)))
					a[4] = chr(ord(a[4]) + 1)
					a[5] = chr(ord(a[5]) + 1)
				a[3] = chr(ord(a[3]) + 1)
				a[6] = chr(ord(a[6]) + 1)
				a[5] = '0'
				a[4] = '0'
			a[2] = chr(ord(a[2]) + 1)
			a[7] = chr(ord(a[7]) + 1)
			a[3] = '0'
			a[4] = '0'
			a[5] = '0'
			a[6] = '0'
		a[1] = chr(ord(a[1]) + 1)
		a[8] = chr(ord(a[8]) + 1)
		a[2] = '0'
		a[3] = '0'
		a[4] = '0'
		a[5] = '0'
		a[6] = '0'
		a[7] = '0'
	a[0] = chr(ord(a[0]) + 1)
	a[9] = chr(ord(a[9]) + 1)
	a[1] = '0'
	a[2] = '0'
	a[3] = '0'
	a[4] = '0'
	a[5] = '0'
	a[6] = '0'
	a[7] = '0'
	a[8] = '0'
arr.append(100000000001)
arr.append(100001100001)
arr.append(100002200001)
ip = input()
k = int(ip.split()[0])
p = int(ip.split()[1])
sum = 0
for i in range(0, k):
	sum = (sum + arr[i]) % p
print(sum)


(k, p) = map(int, input().split())
i = 1
l = []
n = k
while k != 0:
	s = ''
	s = str(i)
	s += s[::-1]
	l.append(s)
	i += 1
	k -= 1
ans = 0
for i in range(0, n):
	ans += int(l[i])
print(ans % p)


def gen_zcy(n):
	return int(str(n) + str(n)[::-1])
(k, p) = map(int, input().split())
sum = 0
for i in range(1, k + 1):
	sum += gen_zcy(i)
	sum %= p
print(sum)


(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	ans = (ans + (i * 10 ** len(str(i)) % p + int(''.join(list(reversed(str(i))))) % p)) % p
print(ans)


(k, p) = map(int, input().split())
z = [int(str(x) + str(x)[::-1]) for x in range(1, 10 ** 5 + 1)]
print(sum(z[:k]) % p)


(number, mod) = list(map(int, input().split()))
summ = 0
for i in range(1, pow(10, 9)):
	if number <= 0:
		break
	summ += int(str(i) + str(i)[::-1])
	number -= 1
print(summ % mod)


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
t = 0
for i in range(1, n + 1):
	x = str(i)
	t += int(x + x[::-1])
print(t % m)


(a, b) = map(int, input().split())
sumx = 0
for i in range(1, a + 1):
	s = str(i)
	l = len(s)
	for j in range(l - 1, -1, -1):
		s = s + s[j]
	i = int(s)
	sumx = sumx + i
print(sumx % b)


(k, p) = map(int, input().split())
counter = 0
n = 0
summa = 0
while counter < k:
	n += 1
	n1 = str(n)
	listN = list(n1)
	reversedN = ''.join(listN[::-1])
	listN.append(reversedN)
	finalN = ''.join(listN)
	finalNN = int(finalN)
	counter += 1
	summa += finalNN
print(summa % p)


def zc(n):
	ans = 0
	for i in range(1, n + 1):
		ok = int(str(i) + str(i)[::-1])
		ans += ok
	return ans
(n, k) = map(int, input().split())
print(zc(n) % k)


(k, p) = map(int, input().split())
count = 0
i = 1
while k > 0:
	count += int(str(i) + str(i)[::-1])
	k -= 1
	i += 1
print(count % p)


from functools import reduce
(k, p) = map(int, input().split())
ans = [0]
for x in range(1, k + 1):
	ans.append(int(str(x) + str(x)[::-1]))
print(reduce(lambda a, b: (a + b) % p, ans))


(k, p) = list(map(int, input().split()))
i = 1
S = 0
while k > 0:
	S += int(str(i) + str(i)[::-1])
	i += 1
	k -= 1
print(S % p)


(k, p) = list(map(int, input().split()))
c = 0
for i in range(1, k + 1):
	s = str(i)
	s_ = s[::-1]
	c += int(s + s_)
	c %= p
print(c)


(k, p) = list(map(int, input('').strip().split()))
answer = 0
before = 0
for i in range(k):
	if before == 0:
		before = 1
	else:
		before += 1
	now = int(str(before) + str(before)[::-1])
	answer = (answer + now) % p
print(answer)


(k, p) = map(int, input().split())
res = 0
for i in range(1, k + 1):
	res += int(str(i) + str(i)[::-1])
print(res % p)


def rev(x):
	s = x
	j = len(x) - 1
	while j >= 0:
		s += x[j]
		j -= 1
	return s

def main():
	(a, b) = map(int, input().split(None, 2)[:2])
	s = 1
	t = 0
	while s <= a:
		p = rev(str(s))
		p = int(p)
		t += p
		s += 1
	print(t % b)
main()


def nice(s):
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - i - 1]:
			return False
			break
	if len(str(s)) % 2 == 0:
		return True
(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	ans += int(str(i) + str(i)[::-1])
print(ans % p)


def main():
	(k, p) = map(int, input().split())
	s = 0
	for i in range(1, k + 1):
		r = str(i)
		w = r[::-1]
		n = int(r + w)
		s += n
	print(s % p)

def __starting_point():
	try:
		main()
	except KeyboardInterrupt:
		pass
__starting_point()


(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	newn = str(i)
	newn = newn + newn[::-1]
	newn = int(newn)
	ans += newn
print(ans % p)


def main(length, r, num, rev, length2):
	global left, res, p
	if length == 0:
		if left == 0:
			return
		res += num * r * 10 + rev
		res %= p
		left -= 1
	else:
		for j in range(10):
			if left == 0:
				return
			main(length - 1, r, num * 10 + j, j * 10 ** length2 + rev, length2 + 1)
(k, p) = map(int, input().split())
left = k
res = 0
indicator = True
for length in range(1, 100):
	if not indicator:
		break
	r = 10 ** (length - 1)
	for i in range(1, 10):
		if left == 0:
			indicator = False
			break
		main(length - 1, r, i, i, 1)
print(res)


def get_zcy(a):
	s = str(a)
	ln = len(s)
	return a * 10 ** ln + int(s[::-1])
(k, p) = list(map(int, input().split()))
print(sum([get_zcy(x) for x in range(1, k + 1)]) % p)


from sys import stdin, stdout

def main(k, p):
	i = 1
	s = 0
	while True:
		s = (s + int(str(i) + str(i)[::-1]) % p) % p
		i += 1
		if i > k:
			break
	return s
stdout.write('{}\n'.format(main(*list(map(int, stdin.readline().strip().split(' '))))))


def create_zcy_for(n):
	zcy_list = []
	start = 10 ** int(n / 2 - 1)
	stop = 10 ** int(n / 2)
	for i in range(start, stop):
		tmp = str(i)
		zcy = int(tmp + tmp[::-1])
		zcy_list.append(zcy)
	return zcy_list

def main():
	nums = [int(n) for n in input().split()]
	k = nums[0]
	p = nums[1]
	counter = 2
	zcy_list = create_zcy_for(counter)
	while len(zcy_list) < k:
		counter += 2
		tmp = create_zcy_for(counter)
		zcy_list = zcy_list + tmp
	res = sum(zcy_list[0:k]) % p
	print(res)
	return res
main()


(k, p) = list(map(int, input().split()))

def to_zcy(i):
	return int(str(i) + str(i)[::-1])

def get_sum():
	result = 0
	for i in range(1, k + 1):
		result += to_zcy(i) % p
		result %= p
	return result
print(get_sum())


def main():
	(k, p) = map(int, input().split())
	r = 0
	for i in range(1, k + 1):
		s = str(i)
		r += int(s + s[::-1])
	print(r % p)
main()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	kp = list(map(int, input().split()))
	(k, p) = (kp[0], kp[1])
	res = [0, 11, 22, 33, 44, 55, 66, 77, 88, 99]
	if k <= 9:
		print(sum(res[1:k + 1]) % p)
	else:
		m = 1
		(cnt, i, t, r) = (9, 1, 0, 0)
		while True:
			for j in range(10):
				if cnt == k:
					break
				x = res[i] // 10 ** m
				y = res[i] % 10 ** m
				x = x * 10 ** (m + 2)
				res.append(res[j] * 10 ** m + x + y)
				t = t + 1
				r = r + 1
				cnt = cnt + 1
			if cnt == k:
				break
			if t == 10:
				t = 0
				i = i + 1
			if r == 9 * 10 ** m:
				r = 0
				m = m + 1
		print(sum(res) % p)
main()


def get_int(string, n):
	i = j = k = 0
	for s in string:
		k += 1
	for s in string:
		if i == n - 1:
			break
		if s == ' ':
			i += 1
		j += 1
	i = 0
	while j < k:
		if string[j] == ' ':
			break
		i = 10 * i + int(string[j])
		j += 1
	return i

def get_zcy(string):
	strin = ''
	for i in string:
		strin = i + strin
	return string + strin
x = input()
k = get_int(x, 1)
p = get_int(x, 2)
sum = 0
for i in range(1, k + 1):
	y = f'{i}'
	y = get_zcy(y)
	sum += int(y)
print(sum % p)


def f(a1):
	if a1 >= 10:
		a = str(a1)
		if a == a[::-1]:
			m = a1 + 1
			a = str(m)
		a1 = int(a)
		q1 = a[:len(a) // 2]
		if len(a) % 2 == 1:
			x = a[len(a) // 2]
		else:
			x = ''
		s = (len(a) % 2 + 2) % (len(a) % 2 + 1)
		q2 = a[len(a) // 2 + s:]
		w = len(q2)
		if int(q2) > int(q1) and (x == '' or x == '9') or int(q1[::-1]) < int(q2):
			a1 += 10 ** w - int(q2)
		elif int(q2) > int(q1) and x != '' and (x != '9'):
			m = int(x) + 1
			x = str(m)
			a1 += 10 ** w - int(q2)
		a = str(a1)
		q1 = a[:len(a) // 2]
		if len(a) % 2 == 1:
			x = a[len(a) // 2]
		else:
			x = ''
		result = q1 + x + q1[::-1]
		return int(result)
	elif a1 == 9:
		return 11
	else:
		return a1 + 1
(k, p) = map(int, input().split())
summ = 0
a1 = 9
for i in range(k):
	a1 = f(a1)
	if len(str(a1)) % 2 == 1:
		a1 = 10 ** len(str(a1))
		a1 = f(a1)
	summ += a1
	summ = summ % p
print(summ % p)


def main():
	(N, K) = map(int, input().split())
	add = 0
	for i in range(1, N + 1):
		string = str(i)
		string = string + string[::-1]
		add += int(string)
		add = add % K
	print(add)
main()


I = map(int, input().split())
(k, p) = I
print(sum((int(str(i) + str(i)[::-1]) for i in range(1, k + 1))) % p)


maxk = 100001
n = 1
zcy = []
while len(zcy) <= maxk:
	zcy.append(int(str(n) + str(n)[::-1]))
	n += 1
s = input().strip().split()
k = int(s[0])
p = int(s[1])
ans = 0
for i in range(k):
	ans = (ans + zcy[i]) % p
print(ans)


n = list(map(int, input().split()))
k = []
s = ''
c = 0
for i in range(n[0]):
	if len(s) == 0:
		s = str(11)
	else:
		for j in range(len(s) // 2 - 1, -1, -1):
			if s[j] == '9':
				s = s[:j] + '0' + s[j + 1:len(s) - 1 - j] + '0' + s[len(s) - j:]
			else:
				s = s[:j] + str(int(s[j]) + 1) + s[j + 1:len(s) - 1 - j] + str(int(s[j]) + 1) + s[len(s) - j:]
				break
		if 1 * int(s) == 0:
			s = '1' + s + '1'
	c = c + int(s)
print(c % n[1])


(k, p) = list(map(int, input().split()))
ans = 0
for n in range(1, k + 1):
	x = n
	y = 0
	z = n
	while 0 < x:
		y *= 10
		y += x % 10
		x //= 10
		z *= 10
	z += y
	ans += z
	ans %= p
print(ans)


(k1, p) = list(map(int, input().split()))
l = [11, 22, 33, 44, 55, 66, 77, 88, 99]
for i in range(1, 10):
	for j in range(0, 10):
		s = str(i) + str(j) + str(j) + str(i)
		num = int(s)
		l.append(num)
for i in range(1, 10):
	for j in range(0, 10):
		for k in range(0, 10):
			s = str(i) + str(j) + str(k) + str(k) + str(j) + str(i)
			num = int(s)
			l.append(num)
for i in range(1, 10):
	for j in range(0, 10):
		for k in range(0, 10):
			for m in range(0, 10):
				s = str(i) + str(j) + str(k) + str(m) + str(m) + str(k) + str(j) + str(i)
				num = int(s)
				l.append(num)
for i in range(1, 10):
	for j in range(0, 10):
		for k in range(0, 10):
			for m in range(0, 10):
				for n in range(0, 10):
					s = str(i) + str(j) + str(k) + str(m) + str(n) + str(n) + str(m) + str(k) + str(j) + str(i)
					num = int(s)
					l.append(num)
l.append(100000000001)
ans = sum(l[:k1])
print(ans % p)


(k, p) = map(int, input().split())
lis = []
for i in range(1, 1000000):
	lis.append(i)
ans = 0

def reverse(s):
	st = ''
	for i in s:
		st = i + st
	return st
for i in range(1000000):
	d = int(str(lis[i]) + reverse(str(lis[i])))
	ans += d
	ans = ans % p
	k -= 1
	if k == 0:
		break
print(ans)


basics = ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']
zcy = [11, 22, 33, 44, 55, 66, 77, 88, 99]
total = 0
(k, p) = map(int, input().split())
if len(zcy) < k:
	for i in zcy:
		for j in basics:
			copy = str(i)
			half = len(copy) // 2
			copy = copy[:half] + j + copy[half:]
			zcy.append(int(copy))
		if len(zcy) >= k:
			break
for i in range(0, k):
	total += zcy[i]
print(total % p)


(n, m) = map(int, input().split())
l = [str(x) for x in range(1, n + 1)]
sum_ele = 0
for i in l:
	i = i + i[::-1]
	sum_ele = (sum_ele + int(i)) % m
print(sum_ele)


def f(n, m):
	d = 0
	for i in range(1, k + 1):
		a = str(i)
		x = str()
		for j in range(len(a)):
			x = x + a[len(a) - 1 - j]
		d = d + int(str(i) + x)
	return d % m
(k, p) = map(int, input().split())
print(f(k, p))


(num, divide) = map(int, input().split())
numnow = 1
addresult = 0
while numnow <= num:
	tempstr1 = str(numnow)
	tempstr2 = tempstr1[::-1]
	zcynum = int(tempstr1 + tempstr2)
	addresult += zcynum
	numnow += 1
reminder = addresult % divide
print(reminder)


import sys
sys.setrecursionlimit(100000000)

def iin():
	return int(input())

def impin():
	return map(int, input().split())

def irrin():
	return [int(x) for x in input().split()]

def imrin(n):
	return [int(input()) for _ in range(n)]
s = 0
(k, p) = impin()
for i in range(1, k + 1):
	s = (s + i * 10 ** len(str(i)) + int(str(i)[::-1])) % p
print(s)


import sys
sys.setrecursionlimit(100000000)
(N, K) = map(int, input().split())
arr = ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']
start = 0
end = 10
while True:
	if end >= 220000:
		break
	temp_start = end
	temp_end = end
	for i in range(10):
		for j in range(start, end):
			arr.append(str(i) + arr[j] + str(i))
			temp_end += 1
			if temp_end >= 220000:
				break
		if temp_end >= 220000:
			break
	start = temp_start
	end = temp_end
result = []
for i in range(len(arr)):
	if arr[i][0] != '0':
		result.append(arr[i])
answer = 0
for i in range(N):
	answer += int(result[i])
	answer %= K
print(answer, flush=True)


(n, p) = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	ans += int(str(i) + str(i)[::-1])
	ans %= p
print(ans)


def len(n):
	s = 0
	while n:
		s += 1
		n //= 10
	return s

def rev(n, leng):
	rev = 0
	for i in range(0, leng):
		rev = rev * 10 + n % 10
		n //= 10
		i += 1
	return rev % p

def cal(n, leng):
	return (n * 10 ** leng + rev(n, leng)) % p
(k, p) = input().split()
k = int(k)
p = int(p)
i = 1
sum = 0
while i <= k:
	sum = (sum + cal(i, len(i))) % p
	i += 1
print(sum)


from string import *
(k, p) = map(int, input().split())
sum = 0
for i in range(1, k + 1):
	s = str(i) + ''.join(reversed(str(i)))
	sum = (sum + int(s) % p) % p
print(sum)


(k, p) = [int(i) for i in input().split()]
ans = 0
for i in range(1, k + 1):
	tmp = str(i)
	n = len(tmp)
	rev = tmp[::-1]
	ans += (i * 10 ** n + int(rev)) % p
print(ans % p)


import math
(k, p) = map(int, input().strip().split(' '))
sm = 0
for i in range(1, k + 1):
	ds = str(i)
	vl = i
	for j in range(len(ds) - 1, -1, -1):
		vl = vl * 10 + int(ds[j])
	sm = (sm + vl) % p
print(sm)


def zcy(end, p):
	i = 1
	while i <= end:
		result = 10 ** int(log10(i) + 1) * i + int(str(i)[::-1])
		print(result, file=sys.stderr)
		yield result
		i += 1
import sys
from math import log10
(k, p) = tuple(map(lambda x: int(x), sys.stdin.readline().split()))
result = sum(zcy(k, p))
print(result % p)


(n, mod) = map(int, input().split())
sum = 0
for i in range(1, n + 1):
	s = str(i)
	num = int(s + ''.join(reversed(s)))
	sum += num
	sum %= mod
print(sum)


def read_input_from_file():
	with open('input.in', 'r') as file:
		lines = file.readlines()
	(k, p) = lines[0].split()
	return (k, p)

def main():
	(k, p) = input().split()
	sum_of_zcy_numbers = 0
	for index in range(1, int(k) + 1):
		number = int(str(index) + str(index)[::-1])
		sum_of_zcy_numbers += number
	output = sum_of_zcy_numbers % int(p)
	print('{}'.format(output))
main()


(k, p) = map(int, input().split())
ret = 0
for i in range(1, k + 1):
	ii = str(i)
	ii = ii[::-1]
	jj = str(i)
	s = jj + ii
	ret = (ret + int(s)) % p
print(ret)


def main():
	(K, P) = map(int, input().split())
	ans = 0
	for i in range(1, K + 1):
		x = str(i) + str(i)[::-1]
		ans = (ans + int(x)) % P
	print(ans)
main()


(k, p) = map(int, input().strip().split(' '))
i = 1
ret = 0
while k:
	ret = ret + int(str(i) + str(i)[::-1])
	k = k - 1
	i = i + 1
print(ret % p)


import sys
import itertools

def readIntLine():
	return [int(i) for i in next(sys.stdin).strip().split()]

def zcy_nums():
	for l in itertools.count(2):
		if l % 2 == 1:
			continue
		half_w = l // 2
		for i in range(10 ** (half_w - 1), 10 ** half_w):
			strd = str(i)
			yield int(strd + strd[::-1])
(k, p) = readIntLine()
nums = zcy_nums()
sum = 0
for _ in range(k):
	sum += next(nums)
	if sum > p:
		sum %= p
print(sum)


(a, b) = map(int, input().split())
s = 0
for i in range(a):
	s += int(str(i + 1) + str(1 + i)[::-1])
print(s % b)


def pow(m):
	t = 1
	for p in range(m):
		t *= 10
	return t
a = [int(q) for q in input().strip().split()]
sum = 0
for k in range(1, a[0] + 1):
	sum += k * pow(len(str(k))) + int(str(k)[::-1])
print(sum % a[1])


(k, p) = input().split()
k = int(k)
p = int(p)
a = 0
for i in range(1, k + 1):
	ls = []
	for j in range(len(str(i))):
		ls.append(str(i)[j])
	ls1 = list(reversed(ls))
	a += int(''.join(ls) + ''.join(ls1)) % p
print(int(a % p))


[k, p] = [int(i) for i in input().split()]
zcy = [11, 22, 33, 44, 55, 66, 77, 88, 99]
i = 0
while len(zcy) < k:
	tmp = str(zcy[i])[:len(str(zcy[i])) // 2]
	for j in ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']:
		zcy.append(int(tmp + j + tmp[::-1]))
		if len(zcy) >= k:
			break
	i += 1
print(sum(zcy[:k]) % p)


(k, p) = input().split()
k = int(k)
p = int(p)
n = 1
a = 0
t = 0
while k:
	a += 1
	if len(str(a)) > n:
		n += 1
		a = int('1' + '0' * (n - 1))
	s = str(a)
	t += int(s + s[::-1])
	k -= 1
print(t % p)


def func(n, m, a):
	i = 0
	n = n + 1
	s = 0
	for i1 in range(10):
		for i2 in range(10):
			for i3 in range(10):
				for i4 in range(10):
					for i5 in range(10):
						for i6 in range(10):
							s = s + i6 * a[0]
							s = s + i5 * a[1]
							s = s + i4 * a[2]
							s = s + i3 * a[3]
							s = s + i2 * a[4]
							s = s + i1 * a[5]
							i = i + 1
							if i >= n:
								return s
						if i5 == 0:
							a[0] = a[0] * 10
					if i4 == 0:
						a[1] = a[1] * 10
				if i3 == 0:
					a[2] = a[2] * 10
			if i2 == 0:
				a[3] = a[3] * 10
		if i1 == 0:
			a[4] = a[4] * 10
the_string = input()
(n1, m1) = the_string.split()
n = int(n1)
m = int(m1)
a = [1, 1, 1, 1, 1, 1]
s = func(n, m, a)
s1 = 0
b = 1
for i in range(n):
	b1 = str(b)
	b2 = b1[::-1]
	s1 = s1 + int(b1 + b2)
	b = b + 1
s1 = s1 % m
print(s1)


(k, p) = map(int, input().split())
s = 0
for c in range(1, k + 1):
	s += int(str(c) + str(c)[::-1])
print(s % p)


a_b = input().split()
a = int(a_b[0])
b = int(a_b[1])
sum = 0
s = 0
if a <= 9:
	for i in range(1, a + 1):
		s += int(str(i) + str(i))
	print(s % b)
elif a <= 99:
	sum = 9
	s = 495
	for i in range(1, 10):
		for k in range(10):
			sum += 1
			s += int(str(i) + str(k) + str(k) + str(i))
			if sum == a:
				print(s % b)
				break
elif a <= 999:
	sum = 99
	s = 495495
	for i in range(1, 10):
		for k in range(10):
			for j in range(10):
				sum += 1
				s += int(str(i) + str(k) + str(j) + str(j) + str(k) + str(i))
				if sum == a:
					print(s % b)
					break
elif a <= 9999:
	sum = 999
	s = 495495495
	for i in range(1, 10):
		for k in range(10):
			for j in range(10):
				for l in range(10):
					sum += 1
					s += int(str(i) + str(k) + str(j) + str(l) + str(l) + str(j) + str(k) + str(i))
					if sum == a:
						print(s % b)
						break
elif a <= 99999:
	sum = 9999
	s = 495495495495
	for i in range(1, 10):
		for k in range(10):
			for j in range(10):
				for l in range(10):
					for m in range(10):
						sum += 1
						s += int(str(i) + str(k) + str(j) + str(l) + str(m) + str(m) + str(l) + str(j) + str(k) + str(i))
						if sum == a:
							print(s % b)
							break
elif a == 100000 and b > a:
	print(495495496)
elif a == 100000:
	print(495495496 % b)
elif a <= 999999:
	sum = 99999
	s = 495495495495495
	for i in range(1, 10):
		for k in range(10):
			for j in range(10):
				for l in range(10):
					for m in range(10):
						for n in range(10):
							sum += 1
							s += int(str(i) + str(k) + str(j) + str(l) + str(m) + str(n) + str(n) + str(m) + str(l) + str(j) + str(k) + str(i))
							if sum == a:
								print(s % b)
								break


def cul(t):
	global sumout, count
	sumout = sumout + int(t)
	count = count + 1

def func(t, l):
	tt = t
	for i in range(10):
		tt = t
		if l == 1 and i == 0:
			continue
		tt = tt + str(i)
		if l == length / 2:
			tt = tt + tt[::-1]
			cul(tt)
			if count == k:
				print(sumout % p)
				quit()
		else:
			func(tt, l + 1)
length = 2
count = 0
sumout = 0
(k, p) = [int(x) for x in input().split()]
while True:
	l = 1
	t = ''
	func(t, l)
	length = length + 2


a = []
a = list(map(int, input().split()))
k = a[0]
p = a[1]
sum = 0
for i in range(1, k + 1):
	s = str(i)
	s += s[::-1]
	n = int(s)
	sum = (sum + n) % p
print(sum)


from itertools import product

def getNext():
	rnglist = [range(1, 10)]
	while True:
		for tupl in product(*rnglist):
			nums = list(tupl)
			n = len(nums)
			ret = sum([(10 ** (2 * i + 1) + 1) * 10 ** (n - i - 1) * nums[n - i - 1] for i in range(len(nums))])
			if ret != 0:
				yield ret
		rnglist += [range(0, 10)]
generator = getNext()
(k, p) = input().split(' ')
(k, p) = (int(k), int(p))
s = 0
for i in range(k):
	t = generator.__next__()
	s = (s + t) % p
print(s)


R = lambda : map(int, input().split())
(k, p) = R()
s = 0
for i in range(1, k + 1):
	x = i
	temp = str(x)
	temp = temp + temp[::-1]
	temp = int(temp)
	s = (s + temp) % p
print(s)


(k, p) = map(int, input().split())
s = 0
while k:
	s += k * 10 ** len(str(k)) + int(str(k)[::-1])
	k -= 1
print(s % p)


(n, m) = [int(c) for c in input().split()]
su = 0
for i in range(1, n + 1):
	t = str(i)
	t1 = t[::-1]
	a = t + t1
	su = su + int(a)
print(su % m)


def modificar(a):
	c = [int(i) for i in a]
	tam = len(a) // 2
	esquerda = tam - 1
	direita = tam
	while esquerda != -1:
		c[esquerda] += 1
		c[direita] += 1
		if c[esquerda] >= 10 and esquerda != 0:
			c[esquerda] = 0
			c[direita] = 0
			esquerda -= 1
			direita += 1
		else:
			break
	if c[0] >= 10:
		c = [1] + [0] * (tam * 2) + [1]
	return [str(i) for i in c]
(k, p) = [int(i) for i in input().split()]
a = ['1', '1']
som = 0
som += int(''.join(a))
k -= 1
while k != 0:
	a = modificar(a)
	som += int(''.join(a))
	k -= 1
print(som % p)


def szy_list():
	n = 0
	while 1:
		n = n + 1
		fore = str(n)
		rear = ''.join(list(reversed(fore)))
		num = int(fore + rear)
		yield num
(num, mod) = map(int, input().split())
f = szy_list()
(x, sum) = [0, 0]
for n in f:
	if x < num:
		sum += n
		x += 1
	else:
		break
print(sum % mod)


(k, p) = input().split()
k = int(k)
p = int(p)
answer = 0
for i in range(k):
	n = str(i + 1)
	answer += int(n + n[::-1])
	answer %= p
print(answer)


def reverse(string):
	string = string[::-1]
	return string
(k, p) = input().split(' ')
k = int(k)
p = int(p)
sum = 0
i = 1
for i in range(1, k + 1):
	w = str(i)
	w = w + reverse(w)
	j = int(w)
	sum = (sum % p + j % p) % p
print(sum)


import sys, math
from itertools import permutations
DEBUG = 0
if DEBUG:
	f = open('input.txt', 'r')
	input = f.readline
else:
	input = sys.stdin.readline

def mp():
	return list(map(int, input().split()))

def main():
	(k, p) = mp()
	ans = 0
	for i in range(1, k + 1):
		ans += int(str(i) + ''.join(list(reversed(str(i)))))
		ans %= p
	print(ans)
main()


def createPalindrome(inp, b):
	n = inp
	palin = inp
	while n > 0:
		palin = palin * b + n % b
		n = n // b
	return palin

def generatePaldindromes(k):
	i = 1
	s = 0
	while k != 0:
		j = createPalindrome(i, 10)
		s = s + j
		i = i + 1
		k -= 1
	print(s % m)
import sys
(k, m) = map(int, sys.stdin.readline().split())
generatePaldindromes(k)


def reverse(n):
	l0 = []
	n0 = n
	for i in range(0, len(str(n))):
		l0.append(int(n) % 10)
		n = int(n) - int(n) % 10
		n = int(n / 10)
	b = 0
	for j in range(0, len(str(n0))):
		b = b + int(l0[j]) * 10 ** (len(str(n0)) - j - 1)
	return b

def summon(n):
	l = []
	a = 0
	for i in range(1, n + 1):
		a = i * 10 ** len(str(i)) + reverse(i)
		l.append(a)
	return l
(k, p) = map(int, input().split())
l = []
l = summon(k)
ini = 0
for q in range(k):
	ini = ini + l[q]
print(ini % p)


(k, p) = map(int, input().split())
z = 9
res = 0
mn = 11
i = 1

def x(i):
	return int(str(i)[::-1])
for i in range(1, k + 1):
	if i < 10:
		res += i * 11
	elif i < 100:
		res += i * 100 + x(i)
	elif i < 10 ** 3:
		res += i * 10 ** 3 + x(i)
	elif i < 10 ** 4:
		res += i * 10 ** 4 + x(i)
	elif i < 10 ** 5:
		res += i * 10 ** 5 + x(i)
	else:
		res += i * 10 ** 6 + x(i)
print(res % p)


def next_zcy(a):
	num = a[:len(a) // 2]
	nxt = str(int(num) + 1)
	return int(nxt + nxt[::-1])

def main():
	(n, p) = map(int, input().split())
	ctr = ans = 0
	num = 11
	while ctr < n:
		ans += num % p
		ctr += 1
		num = next_zcy(str(num))
	print(ans % p)
main()


(n, p) = map(int, input().split())
print(sum((int(str(i) + str(i)[::-1]) for i in range(1, n + 1))) % p)


(k, p) = list(map(int, input().split()))
count = 0
val = 0
for i in range(1, k + 1):
	s = str(i) + str(i)[::-1]
	val = (val + int(s) % p) % p
print(val)


R = lambda : list(map(int, input().split()))
(k, p) = R()
print(sum([int(x + x[::-1]) for x in map(str, range(k + 1))]) % p)


(k, p) = list(map(int, input().split()))
l = []
t = 0
while t < 2 * k:
	l.append(str(t) + str(t)[::-1])
	t += 1
s = list(set([int(i) for i in l]))
s.sort()
print(sum(s[:k + 1]) % p)


(k, p) = map(int, input().split())
answer = 0
while k > 0:
	answer += int(str(k) + str(k)[::-1])
	k = k - 1
print(answer % p)


(t, p) = map(int, input().split(' '))
a = 1
(k, c) = (0, 0)
while k != t:
	b = int(str(a) + str(a)[::-1])
	a += 1
	c += b
	k += 1
print(c % p)


def build(n, p):
	zero = []
	layer = ['']
	lenRes = 0
	res = 0
	while True:
		new_zero = []
		for x in zero:
			new_zero.append('0' + x + '0')
		for x in layer:
			new_zero.append('0' + x + '0')
		new_L = []
		for i in range(1, 10):
			for x in zero:
				new_L.append(str(i) + x + str(i))
				lenRes += 1
				res = (res + int(new_L[-1])) % p
				if lenRes == n:
					return res
			for x in layer:
				new_L.append(str(i) + x + str(i))
				lenRes += 1
				res = (res + int(new_L[-1])) % p
				if lenRes == n:
					return res
		zero = new_zero
		layer = new_L

def main():
	(k, p) = map(int, input().split())
	res = build(k, p)
	print(res)
main()


def calc(k):
	return (2 ** k - 1) * 2 ** (k - 1)

def main():
	(k, p) = map(int, input().split())
	res = 0
	for i in range(k + 1):
		res = (res + int(str(i) + str(i)[::-1])) % p
	print(res)
main()


from string import *
(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	val = str(i) + ''.join(reversed(str(i)))
	ans = ans + int(val) % p
	ans = ans % p
print(ans)


(k, p) = map(int, input().split())
x = 0
import math
for i in range(1, k + 1):
	x += int(str(i) + str(i)[::-1])
print(x % p)


(n, p) = map(int, list(input().split()))
a = []
x = 11
for i in range(9):
	a.append(x * (i + 1))
for i in range(10, 100):
	temp = str(i)
	temp = temp + temp[::-1]
	a.append(int(temp))
for i in range(100, 1000):
	temp = str(i)
	temp = temp + temp[::-1]
	a.append(int(temp))
for i in range(1000, 10000):
	temp = str(i)
	temp = temp + temp[::-1]
	a.append(int(temp))
for i in range(10000, 100000):
	temp = str(i)
	temp = temp + temp[::-1]
	a.append(int(temp))
for i in range(100000, 100010):
	temp = str(i)
	temp = temp + temp[::-1]
	a.append(int(temp))
ans = 0
for i in range(n):
	ans += a[i]
	ans %= p
print(ans)


i = 1
v = []
while i <= 100000.0:
	v.append(int(str(i) + str(i)[::-1]))
	i += 1
(k, p) = map(int, input().split())
print(sum(v[:k]) % p)


line = [int(i) for i in input().split()]
(k, p) = (line[0], line[1])
a = []
a.append(0)
for i in range(1, 100001):
	s = []
	if i < 10:
		s = [0 for i in range(2)]
		s[0] = s[1] = str(i)
		pass
	elif i < 100:
		s = [0 for i in range(4)]
		s[0] = s[-1] = str((i - 10) // 10 + 1)
		s[1] = s[-2] = str((i - 10) % 10)
		pass
	elif i < 1000:
		s = [0 for i in range(6)]
		s[0] = s[-1] = str((i - 100) // 100 + 1)
		temp = (i - 100) % 100
		s[1] = s[-2] = str(temp // 10)
		s[2] = s[-3] = str(temp % 10)
		pass
	elif i < 10000:
		s = [0 for i in range(8)]
		s[0] = s[-1] = str((i - 1000) // 1000 + 1)
		temp = (i - 1000) % 1000
		s[1] = s[-2] = str(temp // 100)
		temp %= 100
		s[2] = s[-3] = str(temp // 10)
		s[3] = s[-4] = str(temp % 10)
		pass
	elif i < 100000:
		s = [0 for i in range(10)]
		s[0] = s[-1] = str((i - 10000) // 10000 + 1)
		temp = (i - 10000) % 10000
		s[1] = s[-2] = str(temp // 1000)
		temp %= 1000
		s[2] = s[-3] = str(temp // 100)
		temp %= 100
		s[3] = s[-4] = str(temp // 10)
		s[4] = s[-5] = str(temp % 10)
		pass
	else:
		s = ['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1']
		pass
	if i > 1:
		a.append(a[i - 1] + int(''.join(s)))
	else:
		a.append(int(''.join(s)))
print(a[k] % p)


(k, p) = map(int, input().split())
list = []
i = 1
v = int()
R = 0
x = 0
s = 0
d = ''
c = ''
if k <= 100000:
	i = 1
	x = 1
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
x = s % p
print(x)


a = input().split()
k = int(a[0])
p = int(a[1])
s = 0
for i in range(1, k + 1, 1):
	z = []
	z1 = []
	b = str(i)
	d = ''
	for j in range(len(b) - 1, -1, -1):
		d = d + str(b[j])
	pal = int(b + d)
	s = s + pal
print(s % p)


(n, p) = [int(i) for i in input().split()]
sum = 0
for i in range(1, n + 1):
	o = []
	k = str(i)
	for j in range(int(len(k))):
		o.append(k[j])
	l = ''.join(o)
	o.reverse()
	m = ''.join(o)
	sum += int(l + m)
print(sum % p)


def generation(n):

	def zcy(i):
		s = str(i)
		s = s + s[-1::-1]
		return int(s)
	r = list()
	for i in range(n):
		r.append(zcy(i + 1))
	return r
(k, p) = map(int, input().split())
l = generation(k)
ans = 0
for i in l:
	ans += i
	ans %= p
print(ans)


def main():
	(k, p) = map(int, input().split())
	table = [0] * (k + 5)
	table[0] = 1
	for i in range(1, k + 5):
		table[i] = table[i - 1] * 10
		table[i] %= p
	ans = 0
	for i in range(1, k + 1):
		d = len(str(i))
		j = list(str(i))
		j.reverse()
		j = int(''.join(j))
		ans += i * table[d] + j
		ans %= p
	print(ans)
main()


(k, p) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	var = str(i)
	var1 = var[::-1]
	var = var + var1
	f = int(var)
	ans = (ans + f) % p
print(ans)


lines = input()
N = eval(lines.split(' ')[0])
mod = eval(lines.split(' ')[1])
s = 0
for i in range(N + 1):
	iStr = str(i)
	reversed_string = iStr[::-1]
	s += int(iStr + reversed_string)
print(s % mod)


(num, divisor) = map(int, input().split())
add = 0
for i in range(0, num):
	i = int(str(i + 1) + str(i + 1)[::-1])
	add += i
res = add % divisor
print(res)


from itertools import product
(k, p) = [int(i) for i in input().split()]
su = 0
d = 1
mk = 9
while mk < k:
	mk += 9 * 10 * d
	d += 1
i = 0
pr = product('0123456789', repeat=d)
next(pr)
for c in pr:
	if i == k:
		break
	c = ''.join(c).lstrip('0')
	j = int(c + c[::-1])
	su = (su + j % p) % p
	i += 1
print(su)


(k, MOD) = map(int, input().split())
ans = 0
for i in range(1, k + 1):
	ans = ans + int(str(i) + str(i)[::-1])
	ans %= MOD
print(ans)


(k, p) = list(map(int, input().split()))
output = 0
n = 1
for i in range(k):
	output += int(str(n) + ''.join(list(reversed(str(n)))))
	n += 1
print(output % p)


(n, mod) = map(int, input().split())
sum = 0
for i in range(1, n + 1):
	s = str(i)
	t = s[::-1]
	sum += int(s + t)
	sum %= mod
print(sum)


(n, p) = map(int, input().split())
sum = 0
a = []
for i in range(1, 10):
	s = str(i)
	s = s + s[::-1]
	a.append(int(s) % p)
for i in range(1, 10):
	for j in range(10):
		s = str(i) + str(j)
		s = s + s[::-1]
		a.append(int(s) % p)
for i in range(1, 10):
	for j in range(10):
		for k in range(10):
			s = str(i) + str(j) + str(k)
			s = s + s[::-1]
			a.append(int(s) % p)
for i in range(1, 10):
	for j in range(10):
		for k in range(10):
			for l in range(10):
				s = str(i) + str(j) + str(k) + str(l)
				s = s + s[::-1]
				a.append(int(s) % p)
for i in range(1, 10):
	for j in range(10):
		for k in range(10):
			for l in range(10):
				for m in range(10):
					s = str(i) + str(j) + str(k) + str(l) + str(m)
					s = s + s[::-1]
					a.append(int(s) % p)
a.append(int('100000000001') % p)
a.append(int('111111111111') % p)
for i in range(n):
	sum += a[i]
	sum = sum % p
print(sum)


import sys
cnt = 1
arr = []
(n, k) = map(int, sys.stdin.readline().strip().split())
while cnt <= n:
	st = str(cnt)
	arr.append(int(st + st[::-1]))
	cnt += 1
cnt = 1
while cnt < n:
	arr[cnt] = (arr[cnt] + arr[cnt - 1]) % k
	cnt += 1
sys.stdout.write(str(arr[n - 1] % k))


l = []
i = 0
s = '1'
while i < 100002:
	l.append(s + s[::-1])
	s = int(s)
	s += 1
	i += 1
	s = str(s)
(n, m) = map(int, input().split())
p = 0
i = 0
while i < n:
	p = (p + int(l[i]) % m) % m
	i += 1
print(p)


(a, p) = map(int, input().split())
print(sum([int(x + x[::-1]) for x in map(str, range(a + 1))]) % p)


def construirPalindromos(k):
	suma = 0
	for i in range(k):
		izq = str(i + 1)
		der = izq[::-1]
		palindromo = int(izq + der)
		suma += palindromo
	return suma
entrada = str(input(''))
split = entrada.split(' ')
k = int(split[0])
p = int(split[1])
print(construirPalindromos(k) % p)


(n, k) = map(int, input().split())
s = 0
for i in range(1, n + 1):
	num = str(i)
	rnum = num[::-1]
	num = num + rnum
	s += int(num)
print(s % k)


(k, p) = list(map(int, input().strip().split()))
res = 0
for i in range(1, k + 1):
	x = str(i)
	x = x + x[::-1]
	res = (res + int(x)) % p
print(res)


import sys
from functools import reduce
(n, k) = map(int, sys.stdin.readline().strip().split())
sys.stdout.write(str(reduce(lambda x, y: (x + y) % k, map(lambda i: int(i + i[::-1]), [str(i) for i in range(1, n + 1)])) % k))


(k, p) = input().split()
k = int(k)
p = int(p)
ans = 0
a = 0
while k > 0:
	a += 1
	a = str(a)
	ans += int(a + a[::-1])
	a = int(a)
	k -= 1
print(ans % p)


(k, p) = [int(i) for i in input().split()]
ans = 0
posi = 0
pq = [11, 22, 33, 44, 55, 66, 77, 88, 99]
for i in range(min(k, 9)):
	ans = (ans % p + pq[i] % p) % p
if k <= 9:
	print(ans % p)
else:
	qnt = 10
	i = 1
	pq = ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']
	while qnt <= k:
		for aux in pq:
			if qnt > k:
				break
			st = str(i)
			add = int(st + aux + st[::-1])
			ans = ans % p + add % p
			ans %= p
			qnt += 1
		i += 1
	print(ans)


import sys
(k, p) = input().split()
p = int(p)
k = int(k)
sum = 0
for i in range(k + 1):
	sum += int(str(i) + str(i)[::-1])
print(sum % p)


def GeneratePalindroms():
	i = 1
	while True:
		ii = 10 * i
		r = range(i, ii)
		for j in r:
			s = str(j)
			yield (s + s[-2::-1])
		for j in r:
			s = str(j)
			yield (s + s[::-1])
		i = ii
(k, p) = input().strip().split()
k = int(k)
p = int(p)
total = 0
for (i, s) in enumerate(GeneratePalindroms(), 1):
	if k <= 0:
		break
	if len(s) % 2 == 0:
		total += int(s)
		k -= 1
print(total % p)


temp = input().split()
num = int(temp[0])
mod = int(temp[1])
runningtotal = 0
for i in range(1, num + 1):
	runningtotal += int(str(i) + str(i)[::-1])
print(runningtotal % mod)


from itertools import *
(k, p) = map(int, input().split())
ss = 0
for i in range(1, k + 1):
	s = str(i)
	num = int(s + ''.join(reversed(s)))
	ss += num
	ss %= p
print(ss)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(K, P) = map(int, input().split())
ans = 0
for v in range(1, K + 1):
	x = str(v)
	x = x + x[::-1]
	x = int(x)
	ans += x
	ans %= P
print(ans)


(k, p) = map(int, input().split())
sum = 0
for i in range(k + 1):
	con = str(i) + ''.join(reversed(str(i)))
	sum += int(con)
print(sum % p)


def next(s):
	n = len(s)
	if s == '9':
		return '11'
	else:
		sa = s[:-(n // 2)]
		sb = s[:n // 2][::-1]
		sp = sa + sb
		if sp > s:
			return sp
		else:
			n1 = (n + 1) // 2
			n2 = n - n1
			num = str(int(s[:n1]) + 1)
			sp = num + num[:n2][::-1]
			return sp
inp = input().split(' ')
k = int(inp[0])
p = int(inp[1])
s = '11'
ans = 0
i = 0
while i < k:
	ans += int(s)
	s = next(s)
	if len(s) % 2:
		s = '1' + '0' * (len(s) - 1) + '1'
	i += 1
print(ans % p)


input1 = input('').split(' ')
k = int(input1[0])
p = int(input1[1])
sumNumbers = 0
for i in range(1, k + 1, 1):
	num = int(str(i) + str(i)[::-1])
	sumNumbers += num
print(sumNumbers % p)


(k, p) = map(int, input().split())
s = 0
for i in range(1, k + 1):
	si = str(i) + ''.join(reversed(str(i)))
	s += int(si)
print(s % p)


def main():
	sum = 0
	input_line = list(map(int, input().split()))
	for n in range(1, input_line[0] + 1):
		str1 = str(n)
		str2 = str1[::-1]
		sum += int(str1 + str2)
	print(sum % input_line[1])
main()


(k, p) = map(int, input().split())
zcy = []
num1 = 1
while len(zcy) != k:
	pal = str(num1) + str(num1)[::-1]
	zcy.append(int(pal))
	num1 += 1
print(sum(zcy) % p)


(k, p) = map(int, input().split())
s = 0
n = 0
half = 1
while n < k:
	s += int(str(half) + str(half)[::-1])
	n += 1
	half += 1
print(s % p)


(k, p) = [int(e) for e in input().split()]
summa = 0
for i in range(1, k + 1):
	summa += int(str(i) + str(i)[::-1])
print(summa % p)


line = input().split()
n = int(line[0])
p = int(line[1])
ans = 0
for i in range(1, n + 1):
	k = str(i)
	a = int(k + k[::-1])
	ans += a
	ans %= p
print(ans)


def gensump(k):
	num = 1
	val = 0
	while num <= k:
		val += int(str(num) + str(num)[::-1])
		num += 1
	return val
(k, p) = map(int, input().split())
print(gensump(k) % p)


(k, p) = map(int, input().split())
c = 0
a = ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']
i = 0
while len(a) < k + 10:
	i += 1
	for j in range(0, 10):
		a.append(str(i) + a[j % 10] + str(i)[::-1])
print(sum(map(int, a[:k + 1])) % p)


def getzcy(inp):
	inp = str(inp)
	return int(inp + inp[::-1])
(k, p) = input().split()
k = int(k)
p = int(p)
sum = 0
for i in range(1, k + 1):
	sum = (sum + getzcy(i)) % p
print(sum)


(k, p) = map(int, input().split())
numDigits = 2
n = 0
first = list('11')

def Next(cur):
	for i in range(len(cur) // 2, len(cur)):
		while int(cur[i]) < 9:
			cur[i] = chr(ord(cur[i]) + 1)
			cur[-i - 1] = cur[i]
			yield cur
			yield Next(cur)
		cur[i] = '0'
		cur[-i - 1] = '0'
	cur.insert(0, '1')
	cur.append('1')
	cur[1:] = ['0'] * (len(cur) - 1)
	cur[-1] = '1'
	yield cur
	yield Next(cur)
a = Next(first)
Sum = 11
for i in range(k - 1):
	Sum += int(''.join(next(a)))
	a = next(a)
print(Sum % p)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(a, b) = map(int, input().split())
s = 0
for i in range(a):
	s += int(str(i + 1) + str(1 + i)[::-1])
print(s % b)


def palindromeString(n):
	s = str(n)
	myList = list(s)
	for i in range(0, len(s)):
		myList.append(s[len(s) - i - 1])
	return int(''.join(myList))
inputLine = input()
inputList = inputLine.split(' ')
k = int(inputList[0])
p = int(inputList[1])
sum = 0
for i in range(1, k + 1):
	sum += palindromeString(i)
print(sum % p)


(k_numbers, mod_p) = [int(x) for x in input().split()]
counter = 0
cur_sum = 0
cur_length = 2
for i in range(1, k_numbers + 1):
	czy = int(str(i) + str(i)[::-1])
	cur_sum += czy
	cur_sum = cur_sum % mod_p
print(cur_sum)


(k, p) = map(int, input().split())
a = []
for i in range(1, k + 1):
	a.append(int(str(i) + str(i)[::-1]))
s = 0
for i in range(k):
	s += a[i]
	s %= p
print(s)


[k, p] = [int(i) for i in input().split()]
i = 1
cout = 0
summ = 0
while cout != k:
	a = str(i)
	cout += 1
	summ += int(a + a[::-1])
	i += 1
print(summ % p)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, p):
	summ = 0
	for i in range(1, n + 1):
		numStr = str(i)
		summ += int(numStr + numStr[::-1])
		summ %= p
	return summ
(n, p) = list(map(int, input().split()))
print(solve(n, p))


(k, p) = [int(x) for x in input().split()]

def zcy(n):
	if str(n) == str(n)[::-1] and len(str(n)) % 2 == 0:
		return True
	else:
		return False

def obrat(n):
	return n * 10 ** len(str(n)) + int(str(n)[::-1])
summa = 0
for i in range(k):
	summa += obrat(i + 1)
print(summa % p)


def chan(y, lrc):
	h = []
	for x in y:
		h.append(x)
	l = int(lrc[0]) - 1
	r = int(lrc[1]) - 1
	for x in range(r - l + 1):
		if h[l] == lrc[2]:
			h[l] = lrc[3]
		l += 1
	return ''.join(h)

def run():
	numbers = input().strip()
	numbers2 = numbers.split(' ')
	res = ''
	suma = 0
	for x in range(int(numbers2[0])):
		res = str(x + 1)
		res += res[::-1]
		suma += int(res)
	print(suma % int(numbers2[1]))
run()


def main():
	ans = 0
	(n, m) = map(int, input().split())
	for i in range(1, n + 1):
		ans += int(str(i) + str(i)[::-1])
	print(ans % m)
main()


(k, p) = map(int, input().strip().split())
cur_sum = 0
for i in range(k + 1):
	num = int(str(i) + str(i)[::-1])
	cur_sum = (cur_sum + num) % p
print(cur_sum)


(k, p) = map(int, input().split())
list = []
i = 1
v = int()
R = 0
x = 0
s = 0
d = ''
c = ''
if k <= 9:
	while i <= k:
		v = 11 * i
		list.append(v)
		i += 1
	for i in list:
		s += i
elif 10 <= k <= 99:
	i = 10
	x = 10
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 495
elif 100 <= k <= 999:
	i = 100
	x = 100
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 495495
elif 1000 <= k <= 9999:
	i = 1000
	x = 1000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 495495495
elif 10000 <= k <= 19999:
	i = 10000
	x = 10000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 495495495495
elif 20000 <= k <= 29999:
	i = 20000
	x = 20000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 15495495455495
elif 30000 <= k <= 39999:
	i = 30000
	x = 30000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 40495495425495
elif 40000 <= k <= 49999:
	i = 40000
	x = 40000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for z in list:
		s += z
	s += 75495495405495
elif 50000 <= k <= 59999:
	i = 50000
	x = 50000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 120495495395495
elif 60000 <= k <= 69999:
	i = 60000
	x = 60000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 175495495395495
elif 70000 <= k <= 79999:
	i = 70000
	x = 70000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 240495495405495
elif 80000 <= k <= 89999:
	i = 80000
	x = 80000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 315495495425495
elif 90000 <= k <= 99999:
	i = 90000
	x = 90000
	while i <= k:
		x = str(x)
		d = x[::-1]
		c = x + d
		c = int(c)
		list.append(c)
		x = int(x)
		x += 1
		i += 1
	for i in list:
		s += i
	s += 400495495455495
else:
	s = 100000000001 + 495495495495495
x = s % p
print(x)


(k, m) = map(int, input().split())
x = 0
for i in range(1, k + 1):
	x += int(str(i) + ''.join(reversed(str(i))))
print(x % m)


(k, p) = map(int, input().split())
i = 1
answer = 0
while i <= k:
	i_ = str(i)
	i_ += i_[::-1]
	i__ = int(i_)
	answer += i__
	i += 1
print(answer % p)


(k, p) = map(int, input().split())
s = 0
for i in range(k):
	j = str(i + 1)
	h = j + j[::-1]
	s += int(h)
print(s % p)


(k, p) = input().split()
k = int(k)
p = int(p)

def zcy(inp):
	res = ''
	for item in inp:
		res += str(item)
	for item in inp[::-1]:
		res += str(item)
	return int(res)
res = 0
nums = [1]
for i in range(0, k):
	res += zcy(nums)
	ch = ''
	for item in nums:
		ch += str(item)
	ch = int(ch)
	ch += 1
	ch = str(ch)
	nums = []
	for item in ch:
		nums.append(int(item))
print(res % p)


(k, p) = input().split(' ')
res = [int(str(x) + ''.join(list(str(x))[::-1])) for x in range(1, int(k) + 1)]
print(sum(res) % int(p))


def is_palindrom(n):
	le = len(n)
	l = 0
	r = le - 1
	for i in range(int(le / 2)):
		if n[l] != n[r]:
			return False
		l += 1
		r -= 1
	return True

def gen_palindrom():
	i = 1
	while True:
		s = str(i)
		s = s + s[::-1]
		i += 1
		yield s
(k, p) = list(map(int, input().split()))
num = 10
u = 10
sum = 0
gen = gen_palindrom()
if p < 11:
	print(0)
else:
	j = 0
	for g in gen:
		sum += int(g)
		j += 1
		if j >= k:
			break
	(d, m) = divmod(sum, p)
	print(m)


import sys
(k, p) = input().split()
k = int(k)
p = int(p)
s = 0
ans = 0
for i in range(1, k + 1):
	s = str(i) + str(i)[::-1]
	ans = (ans + int(s)) % p
print(ans)


(a, b) = map(int, input().split())
s = '11'
k = 11
m = ''
for i in range(a - 1):
	m = str(int(s[0:len(s) // 2]) + 1)
	s = m + m[::-1]
	k += int(s)
print(k % b)


s = input().split()
k = int(s[0])
p1 = int(s[1])
s = 0
t = 11
p = 1
while p < k + 1:
	s1 = str(p)
	s0 = s1[::-1]
	s1 += s0
	s += int(s1)
	p += 1
print(s % p1)


list = []
queries = [int(i) for i in input().split()]
k = int(queries[0])
mod = int(queries[1])
for i in range(1, k + 1):
	i = str(i)
	con = i[::-1]
	new = i + con
	list.append(new)
length = len(list)
sum = 0
for i in range(length):
	sum += int(list[i])
ans = sum % mod
ans = str(ans)
print(ans)


(k, p) = input().split()
k = int(k)
p = int(p)
ans = 0
for i in range(1, k + 1):
	n = i
	m = i
	while n:
		m = m * 10 + n % 10
		n //= 10
	ans += m
print(ans % p)


k = input()
a = k.split(' ')
result = 0
for i in range(1, int(a[0]) + 1):
	s = str(i)
	ss = s + s[::-1]
	result = (result + int(ss)) % int(a[1])
print(result)


(k, p) = [int(i) for i in input().strip().split(' ')]
s = 0
for i in range(1, k + 1):
	s += int(str(i) + str(''.join(list(reversed(str(i))))))
print(s % p)


(k, p) = map(int, input().split())
s = 0
for i in range(1, k + 1):
	stri = str(i)
	x = int(stri + stri[::-1])
	s += x
print(s % p)


(k, p) = map(int, input().split())
num = 1

def toPalindrome():
	global num
	res = str(num) + str(num)[::-1]
	num += 1
	return int(res)
total_sum = 0
for i in range(k):
	total_sum += toPalindrome()
print(total_sum % p)


(K, P) = map(int, input().split())
sums = 0
for i in range(1, K + 1):
	sums += int(str(i) + str(i)[::-1])
	sums %= P
print(sums)


n = input()
(x, y) = n.split()
y = int(y)
su = 0
for i in range(1, int(x) + 1):
	z = int(str(i) + str(i)[::-1])
	su += z
	su %= y
print(su)


(k, p) = map(int, input().split(' '))
su = 0
count = 0
num = 0
while count < k:
	if num:
		f = str(num)
		l = f[::-1]
		su += int(f + l)
		count += 1
	num = num + 1
print(su % p)


(k, p) = map(int, input().split())
add_up = 0
for i in range(1, k + 1):
	i = str(i) + str(i)[::-1]
	i = int(i)
	add_up += i
mod = add_up % p
print(mod)


(k, p) = map(int, input().split())
total = 0
for half_zcy in range(1, k + 1):
	current_zcy = int(str(half_zcy) + str(half_zcy)[::-1])
	total += current_zcy
print(total % p)


masukkan = input().split()
k = int(masukkan[0])
p = int(masukkan[1])
hasil = 0
for i in range(1, k + 1):
	hasil += int(str(i) + str(i)[::-1])
hasil %= p
print(hasil)


(k, p) = map(int, input().split())
result = 0
for i in range(1, k + 1):
	str_i = str(i)
	result += int(str_i + str_i[::-1])
print(result % p)


(k, p) = map(int, input().strip().split())

def next(cur):
	n = len(cur) - 1
	i = n // 2
	cur = cur[:i + 1]
	while i >= 0 and cur[i] == '9':
		cur[i] = '0'
		i -= 1
	if i == -1:
		cur = ['1'] + ['0'] * (n + 1) + ['1']
	else:
		cur[i] = str(int(cur[i]) + 1)
		cur = cur + cur[::-1]
	return cur
count = 1
ans = 11
cur = list('11')
nxt = next(cur)
while count < k:
	ans += int(''.join(nxt))
	ans %= p
	cur = nxt
	nxt = next(cur)
	count += 1
if k == 1:
	ans = 11 % p
print(ans)


(k, p) = list(map(int, input().split()))

def cd(n):
	res = 0
	while n > 0:
		res += 1
		n //= 10
	return res

def rev(n):
	res = 0
	while n > 0:
		res *= 10
		res += n % 10
		res %= p
		n //= 10
	return res
ans = 0
for i in range(1, k + 1):
	ans += i * 10 ** cd(i) + rev(i)
	ans %= p
print(ans)


(k, p) = [int(x) for x in input().strip().split(' ')]
k -= 1
res = 0

def add_(hp, rem_l):
	global k, res
	if k < 0:
		return
	if rem_l == 0:
		rl = hp + hp[::-1]
		v = 0
		for (i, d) in enumerate(rl):
			v += d * pow(10, i)
			v = v % p
		res = (res + v) % p
		k -= 1
		return
	rg = range(10) if len(hp) > 0 else range(1, 10)
	for i in rg:
		add_(hp + [i], rem_l - 1)
cs = 1
while k >= 0:
	add_([], cs)
	cs += 1
print(res)


KveP = input().split(' ')
k = int(KveP[0])
p = int(KveP[1])
toplam = 0

def palindromBul(sayi):
	yazi = str(sayi)
	yaziUzunlugu = len(yazi)
	tersYazi = ''
	for harf in range(yaziUzunlugu):
		tersYazi += yazi[yaziUzunlugu - harf - 1]
	return int(yazi + tersYazi)
for sayi in range(1, k + 1):
	toplam += palindromBul(sayi)
print(toplam % p)


def reverse(l):
	l = str(l)
	k = l[::-1]
	return int(k)

def main():
	(k, p) = input().strip().split()
	su = 0
	zxc = 0
	for i in range(1, int(k) + 1):
		x = len(str(i))
		zxc = i * 10 ** x + reverse(i)
		su = su + zxc
	print(su % int(p))
main()


(k, p) = map(int, input().split())
nums = ['']
l = 2
i = 0
s = 0
found = False
while 1:
	if l == 2:
		arr = '123456789'
	else:
		arr = '0123456789'
	nnums = []
	for nm in nums:
		for d in arr:
			nnm = nm[:l // 2 - 1] + str(d) + str(d) + nm[l // 2 - 1:]
			nnums.append(nnm)
			s += int(nnm)
			i += 1
			s %= p
			if i == k:
				found = True
				break
		if found:
			break
	if found:
		break
	l += 2
	nums = nnums
print(s % p)


(k, p) = map(int, input().split())
j = 2
ans = 0
count = 0
for i in range(1, 10):
	ans += int(str(i) * 2)
	count += 1
	if count == k:
		print(ans % p)
		exit(0)
for i in range(1, 10):
	for j in range(10):
		ans += int(str(i) + str(j) + str(j) + str(i))
		count += 1
		if count == k:
			print(ans % p)
			exit(0)
for i in range(1, 10):
	for j in range(10):
		for l in range(10):
			ans += int(str(i) + str(j) + str(l) * 2 + str(j) + str(i))
			count += 1
			if count == k:
				print(ans % p)
				exit(0)
for i in range(1, 10):
	for j in range(10):
		for l in range(10):
			for m in range(10):
				ans += int(str(i) + str(j) + str(l) + str(m) + str(m) + str(l) + str(j) + str(i))
				count += 1
				if count == k:
					print(ans % p)
					exit(0)
for i in range(1, 10):
	for j in range(10):
		for l in range(10):
			for m in range(10):
				for n in range(10):
					ans += int(str(i) + str(j) + str(l) + str(m) + str(n) + str(n) + str(m) + str(l) + str(j) + str(i))
					count += 1
					if count == k:
						print(ans % p)
						exit(0)
ans += 100000000001
count += 1
if count == k:
	print(ans % p)
	exit(0)


def getsumm(k):
	summ = 0
	chs = [1]
	while k > 0:
		cur = ''
		for i in chs:
			cur += str(i)
		cur = cur[::-1] + cur
		summ += int(cur)
		suc = 0
		for i in range(len(chs)):
			if chs[i] == 9:
				chs[i] = 0
			else:
				suc = 1
				chs[i] += 1
				break
		if not suc:
			chs.append(1)
		k -= 1
	return summ
(k, p) = (int(i) for i in input().split())
sm = getsumm(k)
print(sm % p)


def zcy(n):
	return int(str(n) + str(n)[::-1])
fl = input().split()
k = int(fl[0])
p = int(fl[1])
sum = 0
for i in range(k + 1):
	sum = (sum + zcy(i)) % p
print(sum)


a = input().split(' ')

def invertir(var):
	return var[::-1]
b = 0
contador = 0
for i in range(int(a[0])):
	b += 1
	contador += int(str(b) + invertir(str(b)))
print(contador % int(a[1]))


import sys
kp = sys.stdin.read().split()
k = int(kp[0])
p = int(kp[1])
he = 0
for i in range(1, k + 1):
	if i < 10:
		he += i * 10 + i
	elif i < 100:
		unit = i % 10
		digit = i % 100 // 10
		he += i * 100 + unit * 10 + digit
	elif i < 1000:
		unit = i % 10
		digit = i % 100 // 10
		hundred = i % 1000 // 100
		he += i * 1000 + unit * 100 + digit * 10 + hundred
	elif i < 10000:
		unit = i % 10
		digit = i % 100 // 10
		hundred = i % 1000 // 100
		thousand = i % 10000 // 1000
		he += i * 10000 + unit * 1000 + digit * 100 + hundred * 10 + thousand
	elif i < 100000:
		unit = i % 10
		digit = i % 100 // 10
		hundred = i % 1000 // 100
		thousand = i % 10000 // 1000
		wan = i % 100000 // 10000
		he += i * 100000 + unit * 10000 + digit * 1000 + hundred * 100 + thousand * 10 + wan
	elif i == 100000:
		he += 100000000001
final = he % p
print(final)


def reverse(s):
	s1 = ''
	for i in range(len(s) - 1, -1, -1):
		s1 = s1 + s[i]
	return s1

def main():
	s = input()
	s = list(s.split())
	k = int(s[0])
	p = int(s[1])
	a = 0
	for i in range(1, k + 1):
		s = str(i)
		s1 = reverse(s)
		s = int(s + s1)
		a = (a + s) % p
	print(a % p)
main()


def number_list():
	return list(map(int, input().split()))
(k, p) = number_list()
totsum = 0
for i in range(1, k + 1):
	totsum += int(str(i) + ''.join(reversed(str(i))))
print(totsum % p)


(k, p) = list(map(int, input().strip().split()))
vsota = 0
count = 0
x = 1
while True:
	u = int(str(x) + str(x)[::-1])
	vsota += u
	count += 1
	if count == k:
		break
	x += 1
print(vsota % p)


import math
log10 = lambda x: math.log(x) / math.log(10)
(k, p) = map(int, input().split())
c = 0
tot = 0
n = 1
while c < k:
	b = int(log10(int(str(n) + str(0) + str(n)[::-1]))) % 2
	if b:
		for x in range(0, 10):
			el = int(str(n) + str(x) + str(n)[::-1])
			if c < k:
				tot += el
				tot %= p
				c += 1
	else:
		el = int(str(n) + str(n)[::-1])
		if int(log10(el)) % 2 and c < k:
			tot += el
			tot %= p
			c += 1
	n += 1
print(tot)


def zcy():
	k_p = input()
	(k, p) = k_p.split()
	sum = 0
	for i in range(1, int(k) + 1):
		sum = sum + int(str(i) + str(i)[::-1]) % int(p)
	print(sum % int(p))
zcy()


(k, p) = map(int, input().split())
sum = 0
while k > 0:
	sum += int(str(k) + str(k)[::-1])
	k -= 1
print(sum % p)


def log10(v):
	if v >= 100000:
		return 1000000
	elif v >= 10000:
		return 100000
	elif v >= 1000:
		return 10000
	elif v >= 100:
		return 1000
	elif v >= 10:
		return 100
	else:
		return 10
(k, p) = [int(i) for i in input().split(' ')]
s = sum([m * log10(m) + int(str(m)[::-1]) for m in range(1, k + 1)])
print(s % p)


(k, p) = input().split(' ')
k = int(k)
p = int(p)
b = k * [1]
c = []
m = 0
for i in range(0, k):
	b[i] = i + 1
	c = list(str(b[i]))
	d = c[:]
	d.reverse()
	e = c + d
	H = ''.join(e)
	H = int(H)
	m += H
	c = []
	d = []
	e = []
print(m % p)


def is_palindrome(s):
	if s == reversed(s):
		return True
	return False
(k, p) = map(int, input().split())
num = []
for i in range(k + 1):
	num.append(int(str(i) + str(i)[::-1]))
print(sum(num) % p)


(k, p) = map(int, input().split())
sum = 0
for i in range(1, k + 1):
	cur = int('{}{}'.format(str(i), str(i)[::-1]))
	sum += cur
print(sum % p)


(a, b) = map(int, input().split(' '))
sum = 0
count = 0
num = 0
while count < a:
	if num:
		f = str(num)
		l = f[::-1]
		sum += int(f + l)
		count += 1
	num = num + 1
print(sum % b)


(a, b) = [int(i) for i in str(input()).split(' ')]
count = 0
summ = 0
for i in range(1, a + 1):
	tempo = ''.join([i for i in list(str(i))])
	tempo += ''.join(list(reversed(tempo)))
	summ += int(str(tempo))
	summ %= b
print(summ % b)


(a, b) = map(int, input().split())
d = []
for i in range(1, a + 1):
	s = str(i)
	s0 = s + s[::-1]
	d.append(int(s0))
cc = sum(d)
print(cc % b)


x = input().split()
k = int(x[0])
p = int(x[1])
r = 0
for i in range(1, k + 1):
	t = str(i)
	r += int(t + t[::-1])
print(r % p)


def binexp(x, n, p):
	r = 1
	while n > 0:
		if n % 2 == 1:
			r = r * x % p
		x = x * x % p
		n = n // 2
	return r

def invert(x, pot):
	r = 0
	pot = pot // 10
	while pot > 0:
		r = r * 10
		r += x % 10
		pot = pot // 10
		x = x // 10
	return r
(k, p) = (int(i) for i in input().split())
r = 0
pot = 10
for i in range(1, k + 1):
	if i >= pot:
		pot = pot * 10
	r = (r + i * pot) % p
	r = (r + invert(i, pot)) % p
print(r)


(k, p) = map(int, input().split())
s = 0
for i in range(1, k + 1):
	sr = str(i)
	r = sr[::-1]
	s += int(sr + r)
print(s % p)


def rev(a):
	return a[::-1]
ans = 0
(n, q) = map(int, input().split())
s = '11'
for i in range(n):
	ans += int(s)
	p = str(int(s[:len(s) // 2]) + 1)
	s = p + rev(p)
print(ans % q)


def next_zcy(n):
	l = int(len(n) / 2)
	temp = l
	s = [str(i) for i in str(n)]
	while s[l - 1] == '9' and s[len(n) - l] == '9' and (l > 0):
		s[l - 1] = '0'
		s[len(n) - l] = '0'
		l -= 1
	if l == 0:
		return int(''.join(['1'] + ['0'] * (2 * temp) + ['1']))
	else:
		s[l - 1] = str(int(s[l - 1]) + 1)
		s[len(n) - l] = str(int(s[len(n) - l]) + 1)
		return int(''.join(s))
(n, p) = map(int, input().split())
ctr = ans = 0
num = 11
while ctr < n:
	ans += num % p
	ctr += 1
	num = next_zcy(str(num))
print(ans % p)


def count_zcy(n):
	new_list = 0
	for x in range(1, n + 1):
		buff = str(x)
		new_list += int(buff + buff[::-1])
	return new_list

def main():
	buff = input().split()
	(k, p) = (int(buff[0]), int(buff[1]))
	return count_zcy(k) % p
print(main())


inp = input().split()
k = int(inp[0])
p = int(inp[1])
sum = 0
for i in range(1, k + 1):
	temp = int(str(i) + str(i)[::-1]) % p
	sum += temp
sum %= p
print(sum)


(k, p) = [int(i) for i in input().split()]
l2 = [11 * i % p for i in range(1, 10)]
l4 = [(1001 * i + 110 * j) % p for i in range(1, 10) for j in range(10)]
l6 = [(100001 * i + 10010 * j + 1100 * k) % p for i in range(1, 10) for j in range(10) for k in range(10)]
l8 = [(10000001 * i + 1000010 * j + 100100 * k + 11000 * x) % p for i in range(1, 10) for j in range(10) for k in range(10) for x in range(10)]
l10 = [(1000000001 * i + 100000010 * j + 10000100 * k + 1001000 * x + 110000 * y) % p for i in range(1, 10) for j in range(10) for k in range(10) for x in range(10) for y in range(10)]
l = l2 + l4 + l6 + l8 + l10 + [100000000001]
print(sum(l[:k]) % p)


import sys
from functools import reduce
cnt = 1
arr = []
(n, k) = map(int, sys.stdin.readline().strip().split())
while cnt <= n:
	st = str(cnt)
	arr.append(int(st + st[::-1]))
	cnt += 1
cnt = 1
ans = reduce(lambda x, y: (x + y) % k, arr)
sys.stdout.write(str(ans % k))


def main():
	(k, p) = map(int, input().split())
	sum = 0
	for i in range(1, k + 1):
		sum = (sum + int(str(i) + str(i)[::-1])) % p
	print(sum)
main()


def inp(func=int):
	tmp = list(map(func, input().split()))
	return tmp if len(tmp) > 1 else tmp[0]
(k, p) = inp()
total = 0
for i in map(str, range(k + 1)):
	total += int(i + i[::-1])
	total %= p
print(total)


def read_ints():
	return [int(x) for x in input().split()]

def get_zcy_numbers_with_length(num_length):
	start_num = 10 ** ((num_length - 1) // 2)
	max_num = 10 ** (num_length // 2)
	while start_num < max_num:
		yield int('{}{}'.format(start_num, str(start_num)[::-1]))
		start_num += 1

def get_zcy_numbers(num_numbers):
	num_length = 2
	numbers_returned = 0
	while numbers_returned < num_numbers:
		for num in get_zcy_numbers_with_length(num_length):
			yield num
			numbers_returned += 1
			if numbers_returned >= num_numbers:
				break
		num_length += 2

def main():
	(k, p) = read_ints()
	res = 0
	for num in get_zcy_numbers(k):
		res = (res + num) % p
	print(res)
main()


(k, p) = input().split()
k = int(k)
p = int(p)
i = 1
sum = 0
while k > 0:
	m = int(str(k)[::-1])
	n = k * 10 ** len(str(k))
	sum += m + n
	i += 1
	k -= 1
print(sum % p)


(k, p) = map(int, input('').strip(' ').split(' '))
ans = 0
for i in range(1, k + 1):
	dat = i
	remainder = i
	while True:
		dat = dat * 10 + remainder % 10
		remainder = remainder // 10
		if remainder == 0:
			break
	ans = (ans + dat) % p
print(ans)


import itertools as it
(k, p) = [int(elem) for elem in input().split()]

def build_palindroms(digits):
	global k
	global val
	n = digits // 2
	values = [10 ** (digits - 1 - i) + 10 ** i for i in range(n)]
	for comb in it.product(range(1, 10), *[range(0, 10) for i in range(n - 1)]):
		if not k:
			return False
		for (j, dig) in enumerate(comb):
			val += dig * values[j]
		k -= 1
	return True
val = 0
j = 2
while build_palindroms(j):
	j += 2
print(val % p)


from sys import stdin
(k, p) = list(map(int, stdin.readline().strip().split(' ')))
i = '1'
s = 0
while k > 0:
	s += int(i + i[::-1])
	k -= 1
	i = str(int(i) + 1)
print(s % p)


(k, p) = [int(x) for x in input().split(' ')]
r = 1
ans = 0
for i in range(k):
	w = str(r)
	v = w + w[::-1]
	v = int(v)
	ans = (ans + v) % p
	r += 1
print(ans)


num_digit = 0
num_palindrome = 0
count = 0
n = 0
palindrome = 0
mod = 0
arr_sum = 0
s = input()
(num_palindrome, mod) = map(int, s.split())
while num_palindrome > count:
	count += 1
	remainder = 0
	rev_num = 0
	num_digit = 0
	n = count
	while n != 0:
		n = n // 10
		num_digit += 1
	n = count
	while n != 0:
		remainder = n % 10
		rev_num = rev_num * 10 + remainder
		n = n // 10
	palindrome = count * 10 ** num_digit + rev_num
	arr_sum += palindrome
print(arr_sum % mod)


the_string = input()
(n1, m1) = the_string.split()
n = int(n1)
m = int(m1)
s1 = 0
b = 1
for i in range(n):
	b1 = str(b)
	b2 = b1[::-1]
	s1 = s1 + int(b1 + b2)
	b = b + 1
s1 = s1 % m
print(s1)


(k, p) = map(int, input().split())
sum = 0
while k:
	s = str(k)
	t = s[::-1]
	n = int(s + t)
	sum = (sum + n) % p
	k -= 1
print(sum)


sum = 0
(k, p) = (int(x) for x in input().split(' '))
n = 0
while 1 > 0:
	if n < k:
		for g in range(1, 10):
			if n < k:
				a = 11 * g
				sum = sum + a
				n = n + 1
			else:
				break
		for s in range(1, 10):
			for g in range(0, 10):
				if n < k:
					a = 1001 * s + 110 * g
					sum = sum + a
					n = n + 1
				else:
					break
		for b in range(1, 10):
			for s in range(0, 10):
				for g in range(0, 10):
					if n < k:
						a = 100001 * b + 10010 * s + 1100 * g
						sum = sum + a
						n = n + 1
					else:
						break
		for q in range(1, 10):
			for b in range(0, 10):
				for s in range(0, 10):
					for g in range(0, 10):
						if n < k:
							a = 10000001 * q + 1000010 * b + 100100 * s + 11000 * g
							sum = sum + a
							n = n + 1
						else:
							break
		for w in range(1, 10):
			for q in range(0, 10):
				for b in range(0, 10):
					for s in range(0, 10):
						for g in range(0, 10):
							if n < k:
								a = 1000000001 * w + 100000010 * q + 10000100 * b + 1001000 * s + 110000 * g
								sum = sum + a
								n = n + 1
							else:
								break
		for y in range(1, 10):
			for w in range(0, 10):
				for q in range(0, 10):
					for b in range(0, 10):
						for s in range(0, 10):
							for g in range(0, 10):
								if n < k:
									a = 100000000001 * y + 10000000010 * w + 1000000100 * q + 100001000 * b + 10010000 * s + 1100000 * g
									sum = sum + a
									n = n + 1
								else:
									break
	else:
		break
print(sum % p)


l = []

def start():
	l.append(0)
	for i in range(1, 100001):
		x = str(i)
		y = x + x[::-1]
		l.append(int(y))
	for i in range(1, 100001):
		l[i] += l[i - 1]
start()
m = input().split()
k = m[0]
k = int(k)
p = m[1]
p = int(p)
print(l[k] % p)


s = input().split(' ')
n = int(s[0])
mod = int(s[1])
res = 0
for i in range(1, n + 1):
	temp1 = str(i)
	temp2 = str(temp1[::-1])
	temp3 = temp1 + temp2
	temp3 = int(temp3)
	res = (res % mod + temp3 % mod) % mod
print(res)


[k, p] = map(int, input().split())
gg = 1
ans = 0
for i in range(k):
	s = str(gg)
	t = s[::-1]
	s += t
	ans += int(s)
	ans %= p
	gg += 1
print(ans)


import sys

def generar_zcy(res, num_cifras, maximo=100000):
	if num_cifras % 2 != 0:
		return
	lim_inf = int(10 ** (num_cifras / 2 - 1))
	lim_sup = lim_inf * 10
	for num in range(lim_inf, lim_sup):
		if len(res) >= maximo:
			break
		s = str(num)
		res.append(s + s[::-1])
linea = sys.stdin.readline()
(k, p) = [int(num) for num in linea.split()]
res = []
generar_zcy(res, 2, k)
generar_zcy(res, 4, k)
generar_zcy(res, 6, k)
generar_zcy(res, 8, k)
generar_zcy(res, 10, k)
generar_zcy(res, 12, k)
suma = 0
for (i, elem) in enumerate(res):
	suma = (suma + int(elem)) % p
print(suma)


from itertools import permutations
(m, n) = map(int, input().split())
sum = 0
for i in range(1, m + 1):
	sum += int(str(i) + str(i)[::-1])
print(sum % n)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, k) = ei()
ans = 0
for i in range(1, n + 1):
	ans += int(str(i) + str(i)[::-1])
op(ans % k)


(k, p) = [int(i) for i in input().split()]
l = []
for i in range(9):
	l.append((i + 1) * 11 % p)
for i in range(9):
	sum = (i + 1) * 1001 % p
	for j in range(10):
		l.append((sum + 110 * j) % p)
for i in range(9):
	sum = (i + 1) * 100001 % p
	for j in range(10):
		sum1 = (sum + j * 10010) % p
		for q in range(10):
			l.append((sum1 + q * 1100) % p)
for i in range(9):
	sum = (i + 1) * 10000001 % p
	for j in range(10):
		sum1 = (sum + j * 1000010) % p
		for q in range(10):
			sum2 = (sum1 + q * 100100) % p
			for w in range(10):
				l.append((sum2 + w * 11000) % p)
for i in range(9):
	sum = (i + 1) * 1000000001 % p
	for j in range(10):
		sum1 = (sum + j * 100000010) % p
		for q in range(10):
			sum2 = (sum1 + q * 10000100) % p
			for w in range(10):
				sum3 = (sum2 + w * 1001000) % p
				for e in range(10):
					l.append((sum3 + e * 110000) % p)
l.append(100000000001 % p)
sum = 0
for i in range(k):
	sum = (sum + l[i]) % p
print(sum)


a = []
a = ['00']
for i in range(1, 10):
	a.append(i * 11)
d = 4
l = 1
ce = 9
n = 9
while n < 100001:
	ce = n
	for i in a[l:]:
		for j in a[0:10]:
			s = str(i)[:d // 2 - 1] + str(j) + str(i)[d // 2 - 1:]
			a.append(int(s))
			n += 1
			if n > 100001:
				break
	l = ce + 1
	d += 2
ss = [a[1]]
for i in range(2, len(a)):
	ss.append(ss[i - 2] + int(a[i]))
a = [int(i) for i in input().split()]
print(ss[a[0] - 1] % a[1])