#include <bits/stdc++.h>
using namespace std;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230;
template <class T>
int getbit(T s, int i) {
  return (s >> 1) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
long long k, p, ans = 0;
long long digitnum(long long z) {
  long long res = 0;
  while (z > 0) {
    res++;
    z /= 10;
  }
  return res;
}
long long palin(long long z) {
  long long res = 0;
  while (z > 0) {
    res = res * 10 + z % 10;
    z /= 10;
  }
  return res;
}
void VarInput() { cin >> k >> p; }
void ProSolve() {
  for (long long i = 1; i <= k; i++) {
    long long tmp = i;
    if (digitnum(i) == 1)
      tmp = tmp * 10 + palin(tmp);
    else if (digitnum(i) == 2)
      tmp = tmp * 100 + palin(tmp);
    else if (digitnum(i) == 3)
      tmp = tmp * 1000 + palin(tmp);
    else if (digitnum(i) == 4)
      tmp = tmp * 10000 + palin(tmp);
    else if (digitnum(i) == 5)
      tmp = tmp * 100000 + palin(tmp);
    else if (digitnum(i) == 6)
      tmp = tmp * 1000000 + palin(tmp);
    else if (digitnum(i) == 7)
      tmp = tmp * 10000000 + palin(tmp);
    ans = (ans + tmp) % p;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  VarInput();
  ProSolve();
  return 0;
}
