#include <bits/stdc++.h>
using namespace std;

int const M = 1e9 + 7;
vector<int> memo(5500000, -1);
string K; int D;

int count(size_t i, int total, bool upto) {
	if (i == K.size()) return total == 0;

	// 14 bits for index, 7 bits for total, 1 bit for upto
	int key = (i << 9) + (total << 1) + upto;
	if (memo[key] >= 0) return memo[key];

	int sum = 0, leading = K[i] - '0';
	for (int digit = 0; digit <= (upto ? leading : 9); ++digit) {
		if (digit == leading)
			sum += count(i+1, (total+digit) % D, upto);
		else
			sum += count(i+1, (total+digit) % D, false);
		sum %= M;
	}

	return memo[key] = sum;
}

int main() {
	ios_base::sync_with_stdio(false);

	getline(cin, K);
	cin >> D;

	int answer = count(0, 0, true) - 1;
	if (answer < 0) answer += M;
	cout << answer << endl;
}

#include <bits/stdc++.h>

#define name "vd"
#define ini freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define oo 1e9 + 7;
#define PII pair<int, int>
#define long long long
using namespace std;

const int NMAX = 1e4 + 5;
const int MOD = 1e9 + 7;
string s;
int d, n, nxt;
long dp[NMAX][2][105];

int main()
{
    //ini;
    fastio;
    cin >> s >> d;
    n = s.size();
    s = "0" + s;

    memset(dp, 0, sizeof dp);

    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int lss = 0; lss <= 1; lss++){
            for (int j = 0; j < d; j++){
                for (int dg = 0; dg <= 9; dg++){
                    if (!dp[i - 1][lss][j]) continue;
                    if (!lss && dg > (s[i] - '0')) continue;

                    if (!lss && dg == (s[i] - '0')) nxt = 0;
                    else nxt = 1;

                    dp[i][nxt][(j + dg) % d] += dp[i - 1][lss][j] % MOD;
                }
            }
        }
    }

    cout << ((dp[n][0][0] + dp[n][1][0] - 1) % MOD + MOD) % MOD;
    return 0;
}
