#include using namespace std; struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init; const int mod=1e9+7; int main() { string S; int M; cin >> S >> M; int n = S.size(); vector dp(M,0); int ten=10%M; int res=0; for(int i = 0; i < n; i++){ auto nxt=dp; int np=(S[i]-'0'); if(np!=0)nxt[np%M]++; else res++; np%=M; for(int j = 0; j < M; j++){ nxt[np]+=dp[j]; if(nxt[np]>=mod)nxt[np]-=mod; np+=ten; if(np>=M)np-=M; //cout << np << " " << nxt[np] << endl; } swap(dp,nxt); } cout << (res+dp[0])%mod << endl; return 0; }