#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long a[N];
int tot;
int cal(int x) {
  int ans = 0;
  do {
    ans = ans * 10 + x % 10;
    x /= 10;
  } while (x);
  return ans;
}
void init() {
  for (int i = 1; i <= 9; i++) a[++tot] = i * 1LL * 10 + i;
  for (int i = 10; i <= 99; i++) a[++tot] = i * 1LL * 100 + cal(i);
  for (int i = 100; i <= 999; i++) a[++tot] = i * 1LL * 1000 + cal(i);
  for (int i = 1000; i <= 9999; i++) a[++tot] = i * 1LL * 10000 + cal(i);
  for (int i = 10000; i <= 99999; i++) a[++tot] = i * 1LL * 100000 + cal(i);
  a[100000] = 100000000001LL;
}
int main() {
  init();
  int k, p;
  while (scanf("%d%d", &k, &p) != EOF) {
    long long sum = 0;
    for (int i = 1; i <= k; i++) sum = (sum + a[i]) % p;
    printf("%lld\n", sum);
  }
  return 0;
}
