#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll func(ll i, ll curr, ll sum, ll k, ll bounded, vector<ll> &vect) {
if(i==vect.size()) {
if(curr%k!=0 && sum%k==0) return 1;
return 0;
}
ll res=0;
if(bounded) {
for(ll j=0;j<vect[i];j++) {
res+=func(i+1, curr*10+j, sum+j, k, 0, vect);
}
res+=func(i+1, curr*10+vect[i], sum+vect[i], k, 1, vect);
}
else {
for(ll j=0;j<=9;j++) {
res+=func(i+1, curr*10+j, sum+j, k, 0, vect);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k;cin >> n >> k;
ll temp=n;
vector<ll> vect;
while(temp) {
vect.push_back(temp%10);
temp/=10;
}
reverse(vect.begin(), vect.end());
cout << func(0, 0, 0, k, 1, vect);
return 0;
}