#include <bits/stdc++.h>
using namespace std;
long long i, j, n, m, k, p, y, w, c, t;
long long x[20] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int main() {
  cin >> k >> p;
  for (i = 1; i <= k; i++) {
    t = i;
    y = 0;
    j = 0;
    while (t) {
      y *= 10;
      y += t % 10;
      t /= 10;
      j++;
    }
    c += i * x[j] + y;
    c %= p;
  }
  cout << c << endl;
}
