#include using namespace std; using ll = long long; int main() { ll n, p; cin >> n >> p; ll res; vector vec(n,false); if (n >= 110000) { for (ll i = 110000; i < min(n + 1, 999999ll); i++) { string s = to_string(i); if ((s[0] == s[1]) && (s[2] == s[5]) && (s[3] == s[4])) { ll z = n / i; for (int j = 0; j <= z; j++) { if (vec[i * j] == false) { vec[i * j] = true; res += i * j; } } } } cout << ((-1) * res) % p << endl; } else { cout << 0 << endl; } return 0; }