P = 10 ** 9 + 7 T = input() D = int(input()) s = - D c = 0 z = 1 for t in T: if t == "?": c += 1 elif t != "0": z = 0 s += int(t) s %= 9 if D == 0: print(z) else: print(((pow(10, c, P) + (-1 if s else 8)) * pow(9, P-2, P) - (D == 9) * z) % P)