#include char S[100100]; int D; long long C[9] = { 1, }, P[9]; int main() { scanf ("%s %d", S, &D); if (D == 0){ bool g = 1; for (int i = 0; S[i]; i++){ if (S[i] == '?' || S[i] == '0'); else g = 0; } puts(g ? "1" : "0"); return 0; } int s = 0; const long long mod = 1000000007; for (int i = 0; S[i]; i++){ if (S[i] == '?'){ for (int j = 0; j < 9; j++) P[j] = 0; for (int j = 0; j < 9; j++) for (int k = 0; k < 10; k++){ P[(j + k) % 9] = (P[(j + k) % 9] + C[j]) % mod; } for (int j = 0; j < 9; j++) C[j] = P[j]; } else s += S[i] - '0'; } if (D == 9) D = 0; printf ("%lld\n", C[(D + 9 - s) % 9]); return 0; }