#include <bits/stdc++.h>
using namespace std;
const long long POW[] = {
    1LL,
    10LL,
    100LL,
    1000LL,
    10000LL,
    100000LL,
    1000000LL,
    10000000LL,
    100000000LL,
    1000000000LL,
    10000000000LL,
    100000000000LL,
    1000000000000LL,
    10000000000000LL,
    100000000000000LL,
    1000000000000000LL,
    10000000000000000LL,
    100000000000000000LL,
    1000000000000000000LL,
};
long long k, p;
long long solve(long long a, long long len) {
  long long b = 0, t = a;
  while (t) {
    b = b * 10 + t % 10;
    t /= 10;
  }
  return a * POW[len] + b;
}
int main() {
  cin >> k >> p;
  long long cnt = 0;
  long long sum = 0;
  for (long long i = 1; cnt < k; i++)
    for (long long j = POW[i - 1]; j < POW[i] && cnt < k; j++, cnt++)
      sum = (sum + solve(j, i)) % p;
  cout << sum << endl;
}
