#include <bits/stdc++.h>
using namespace std;
int INV(int k) {
  int ans = 0;
  while (k) {
    ans = ans * 10 + k % 10;
    k /= 10;
  }
  return ans;
}
int main() {
  int k, p;
  long long sum = 0;
  cin >> k >> p;
  int len = 0, base = 1;
  for (int i = 1; i <= k; ++i) {
    if (i % base == 0) base *= 10, ++len;
    sum += (1ll * i * base + INV(i)) % p;
    sum %= p;
  }
  cout << sum << endl;
  return 0;
}
