#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long k, p, ats = 0;
  cin >> k >> p;
  set<long long> S;
  for (int i = 1; S.size() < k; i++) {
    stringstream ss;
    ss << i;
    string s;
    ss >> s;
    string r = s;
    reverse(r.begin(), r.end());
    s += r;
    ss.clear();
    ss << s;
    long long x;
    ss >> x;
    S.insert(x);
  }
  for (auto x : S) ats = (ats + x) % p;
  cout << ats << "\n";
}
