#include using namespace std; long long dp[2][20001]; int nex[20001][10]; int M = 1000000007; int main(){ string s; cin >> s; int n = s.length(), m; cin >> m; long long zero = -1; dp[0][0] = 1; for (int i = 0; i < m; ++i) { for (int j = 0; j < 10; ++j) { nex[i][j] = (i * 10 + j) % m; } } for (int i = 0, ii = 0; i < n; ++i, ii ^= 1) { int t = s[i] - '0'; int ij = ii ^ 1; for (int j = 0; j < m; j++) { dp[ij][j] += dp[ii][j]; dp[ij][nex[j][t]] += dp[ii][j]; } if (!t) { dp[ij][0] = (dp[ij][0] + M - 1) % M; ++zero; } for (int j = 0; j < m; ++j) { dp[ij][j] %= M; dp[ii][j] = 0; } } cout << (dp[n & 1][0] + zero + M) % M << "\n"; return 0; }