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