#include <bits/stdc++.h>
using namespace std;
bool isFinished(string s) {
  int sz = s.size();
  for (int i = 0; i < sz; ++i)
    if (s[i] != '9') return false;
  return true;
}
string findNext(string s) {
  int sz = s.size();
  if (isFinished(s)) {
    s[0] = '1';
    for (int i = 1; i < sz; ++i) s[i] = '0';
    s += '1';
    return s;
  } else {
    int temp = sz / 2;
    do {
      if (s[temp] != '9') break;
    } while (temp++ < sz);
    s[temp]++, s[sz - 1 - temp]++;
    if (sz % 2 == 1 && temp == sz / 2) s[temp]--;
    for (int j = sz - temp; j < temp; ++j) s[j] = '0';
    return s;
  }
}
int main() {
  int k, p;
  cin >> k >> p;
  long long res = 0;
  string start = "11";
  while (k--) {
    res += stoll(start) % p;
    start = findNext(start);
    while (start.size() % 2 == 1) {
      start = findNext(start);
    }
  }
  res %= p;
  cout << res << endl;
}
