#include <bits/stdc++.h>
long long strange[100001];
int main() {
  for (int i = 1; i <= 100000; i++) {
    long long a = i, b = i;
    while (b) {
      a *= 10;
      a += b % 10;
      b /= 10;
    }
    strange[i] = a;
  }
  long long k, p;
  while (scanf("%lld%lld", &k, &p) != EOF) {
    long long sum = 0;
    for (int i = 1; i <= k; i++) sum += strange[i];
    printf("%lld\n", sum % p);
  }
}
