#include <cstdio>
using namespace std;

int main()
{
	long long a, mul = 10, res = 1, cur = 1, mod;
	int b;

	scanf("%lld%d", &a, &b);
	mod = 1ll * b * b;

	while (cur <= a)
	{
		if (cur & a)
			res = (res * mul) % mod;
		
		mul = (mul * mul) % mod;
		cur <<= 1;
	}

	printf("%lld\n", res / b);

	return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int M = 10005;
typedef __int128 ll;
typedef __int128 lll;

ll n;
int m;

ll inv[M];
map<ll, int> book;

inline void init() {
	inv[1] = 1;
	for (int i = 2; i <= m; i++) {
		inv[i] = (m - m/i) * inv[m%i] % m;
	}
}

inline ll qpow(ll a, ll b, ll p) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}

int main()
{
	long long tn, tm;
	scanf("%lld%lld", &tn, &tm);
	n = tn, m = tm;
	
	
	init();
	
	ll x = 1;
	ll a = 0, b = 0;
	ll c = 0, d = 0, len = -1;
	
	while (c < n) {
		x *= 10;
		c++;
		a = (a * 10 % m + x / m % m) % m;
		x %= m;
		if (book[x]) {
			len = c - book[x];
			break;
		}
		book[x] = c;
	}
	
	if (c >= n) {
		printf("%lld", (long long)a);
		return 0;
	}
	
	x = 1;
	for (int i = 1; i <= c-len; i++) {
		x *= 10;
		x %= m;
	}
	
	while (d < len) {
		x *= 10;
		d++;
		b = (b * 10 % m + x / m % m) % m;
		x %= m; 
	}
	
//	printf("c = %lld, len = %lld, x = %lld\n", c, len, x);
//	printf("a = %lld, b = %lld\n", a, b);
	
	ll k = (n - c) / len;
	ll t = qpow(10, len, m);
	
//	printf("k = %lld, t = %lld\n", k, t);
	
	ll ans = 0;
//	if (t == 1) ans = k;
//	else ans = (lll)((1ll - qpow(t, k, m)) % m + m) % m * (lll)inv[((1ll-t)%m+m)%m] % m;
//	ans = (lll)ans * (lll)b % m;
	ans = (lll)k * (lll)b % m;
	
	
//	printf("ans = %lld\n", ans);
	
	ans = (ans + a * qpow(t, k+1, m) % m) % m;
	
	ll r = (n-c) % len;
	
	d = 0;
	while (d < r) {
		x *= 10;
		d++;
		ans = (ans * 10 % m + x / m % m) % m;
		x %= m;
	}
	
	printf("%lld", (long long)ans);
	
	return 0;
}