#include using namespace std; #define rep(i,n) for(int i=0;i dx = {0,1,0,-1} , dy = {1,0,-1,0}; //chmin , chmax template bool chmin(T &a , T b){ if(a > b){a = b ; return 1;} return 0; } template bool chmax(T &a , T b){ if(a < b){a = b ; return 1;} return 0; } //io template std::istream& operator>>(std::istream& is , pair &p){ is >> p.first >> p.second; return is; } template std::ostream& operator<<(std::ostream& os , const pair &p){ os << " [" << p.first << " : " << p.second << "] "; return os; } //vio template void printv(vector &v){ rep(i,(int)v.size()){ cout< void printvv(vector> &vv){rep(i,(int)vv.size()) printv(vv[i]);} template void printve(vector &v){ rep(i,(int)v.size()){ cerr< void printvve(vector> &vv){rep(i,(int)vv.size()) printve(vv[i]);} template void vin(vector &v){for(auto &vi : v) cin>>vi;} template void vvin(vector> &vv){for(auto &vvi : vv) vin(vvi);} int main(){cin.tie(0);ios::sync_with_stdio(0); ll n , p; cin >> n >> p; vector otogi; for(int i=1;i<10;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++){ // iijkkj int t = 110000 * i + 1001 * j + 110 * k; otogi.push_back(t); } ll ans = 0; set used; using P = pair; priority_queue

, greater

> pq; for(auto oi : otogi) pq.push(make_pair(oi , oi)); while(!pq.empty()){ ll sum , unit; tie(sum , unit) = pq.top();pq.pop(); if(sum > n) continue; if(!used.count(sum)){ used.insert(sum); ans -= sum; ans %= p; } pq.push(make_pair(sum + unit , unit)); } ans += p; ans %= p; cout << ans << endl; }