#include <bits/stdc++.h>
using namespace std;
int k, p;
int f[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int main() {
  scanf("%d%d", &k, &p);
  long long tot = 1, ans = 0;
  while (tot <= k) {
    long long x = tot, y = 0, m = 0;
    while (x) {
      m++;
      y = y * 10 + x % 10;
      x /= 10;
    }
    ans = (ans + tot * f[m] + y) % p;
    tot++;
  }
  printf("%I64d\n", ans);
  return 0;
}
