#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, p;
  vector<string> v;
  string s, ss;
  cin >> k >> p;
  int cnt = 0;
  for (int i = 1; i <= 100000; ++i) {
    string s = to_string(i);
    string ss = s;
    reverse(ss.begin(), ss.end());
    s = s + ss;
    v.push_back(s);
  }
  long long ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += stoll(v[i]);
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}
