#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,mod;
struct node{
LL a[4][4];
node operator * (const node &b) const {
node c;
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
c.a[i][j]=0;
for(int k=1;k<=3;k++) c.a[i][j]=(c.a[i][j]+(a[i][j])%mod*(b.a[j][k])%mod)%mod;
}
}
return c;
}
};
node cao(){
node b;
for(int i=1;i<=3;i++) b.a[i][i]=1;
return b;
}
node init(int k){
node sum;
sum.a[1][1]=k%mod;
sum.a[1][2]=1;
sum.a[1][3]=1;
sum.a[2][2]=1;
sum.a[2][3]=1;
sum.a[3][3]=1;
return sum;
}
node pow(node G,LL p){
node ans=cao();
for(;p!=0;p>>=1,G=G*G) if(p&1) ans=ans*G;
return ans;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(0);std::cout.tie(0);
cin>>n>>mod;
LL x=10;
node ans=cao();
while(x<=n){
ans=ans*pow(init(x),x-x/10);
x=x*10;
}
ans=ans*pow(init(x),n-x/10+1);
cout<<ans.a[1][3]<<endl;
return 0;
}