#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
template <typename T>
std::string NumberToString(T Number) {
  std::ostringstream ss;
  ss << Number;
  return ss.str();
}
long long int StringToNumber(string Text) {
  stringstream ss(Text);
  long long int result;
  return ss >> result ? result : 0;
}
string evenlength(string n) {
  string res = n;
  for (int j = n.length() - 1; j >= 0; --j) res += n[j];
  return res;
}
long long int findSum(int number) {
  long long int sum = 0;
  for (int i = 1; i <= number; i++) {
    string n = NumberToString(i);
    long long int a = StringToNumber(evenlength(n));
    sum += a;
  }
  return sum;
}
int main() {
  long long int k, p;
  cin >> k >> p;
  long long int temp = findSum(k) % p;
  cout << temp << endl;
  return 0;
}
