#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
string st;
int64_t k, p;
int64_t arr[N], ten = 10, su = 0, ans;
int main() {
  cin >> k >> p;
  for (int i = 1; i <= 100000; i++) {
    if (i % ten == 0) {
      ten *= 10;
    }
    int64_t num, tten = ten / 10;
    num = i * ten;
    int j = i;
    while (j > 0) {
      num += ((j % 10) * tten);
      tten /= 10;
      j /= 10;
    }
    arr[i - 1] = num;
  }
  for (int i = 0; i < k; i++) {
    su += arr[i];
  }
  ans = su % p;
  cout << ans;
  return 0;
}
