#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, p, nr = 1, ogl = 0, x, cifra = 1, test = 10, y = 0, b;
  unsigned long long ans = 0;
  ios_base::sync_with_stdio(false);
  cin >> a >> p;
  while (a) {
    x = cifra;
    y = nr;
    b = nr;
    while (x) y = y * 10 + b % 10, b /= 10, --x;
    ans += y;
    ++nr;
    if (nr == test) ++cifra, test *= 10;
    --a;
  }
  cout << ans % p;
  return 0;
}
