import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); char[] t = sc.next().toCharArray(); int d = sc.nextInt(); sc.close(); int sum = 0; int cnt = 0; for (int i = 0; i < t.length; i++) { if (t[i] == '?') { cnt++; } else { sum += t[i] - '0'; } } if (d == 0) { if (sum == 0) { System.out.println(1); } else { System.out.println(0); } return; } if (d == 9 && cnt == 1) { System.out.println(1); return; } int mod = 1000000007; long[][] dp = new long[cnt + 1][9]; dp[0][0] = 1; for (int i = 0; i < cnt; i++) { for (int j = 0; j < 9; j++) { for (int j2 = 0; j2 < 10; j2++) { dp[i + 1][(j + j2) % 9] += dp[i][j]; } } for (int j = 0; j < 9; j++) { dp[i + 1][j] %= mod; } } sum %= 9; if (cnt == 0) { throw new Exception(); } int c = (d - sum + 9) % 9; System.out.println(dp[cnt][c]); } }