#include <bits/stdc++.h>
using namespace std;
long long rev(long long x) {
  long long pp = x;
  while (x) {
    pp = (pp * 10) + (x % 10);
    x /= 10;
  }
  return pp;
}
int main() {
  long long k, p, coun = 0;
  long long ans = 0;
  cin >> k >> p;
  for (int i = 1; coun < k; i++) {
    long long ii = rev(i);
    ans = (ans + (ii % p)) % p;
    coun++;
  }
  cout << ans;
  return 0;
}
