#include <bits/stdc++.h>
int main() {
  long long n, p, s = 0, t, a[100];
  std::cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    t = i;
    long long k = 0, h = 1;
    while (t) a[++k] = t % 10, t /= 10;
    for (int i = k; i >= 1; i--) t += h * a[i], h *= 10;
    t += i * h;
    s = (s + t) % p;
  }
  std::cout << s << std::endl;
}
