#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, p;
  while (~scanf("%lld%lld", &k, &p)) {
    long long sum = 0;
    for (int i = 1; i <= k; i++) {
      long long j = i;
      long long q = i;
      while (q) {
        j = (j * 10 + q % 10) % p;
        q /= 10;
      }
      sum = (sum + j) % p;
    }
    printf("%lld\n", sum);
  }
  return 0;
}
