#include <bits/stdc++.h>
using namespace std;
long long lg(long long a) {
  long long i = -1;
  while (a) {
    i++;
    a /= 10;
  }
  return i;
}
long long pow10(long long a) {
  long long i = 1;
  while (a) {
    i *= 10;
    a--;
  }
  return i;
}
long long rv(long long a) {
  long long i = 0;
  while (a) {
    i = i * 10 + a % 10;
    a /= 10;
  }
  return i;
}
int main() {
  long long k, p, pw = 0, ans = 0, cr = 1;
  cin >> k >> p;
  while (k) {
    long long tmp = (cr * pow10(lg(cr) + 1) + rv(cr));
    ans = (ans + tmp) % p;
    k--;
    cr++;
  }
  cout << ans;
  return 0;
}
