import numpy as np T = input() D = int(input()) MOD = 10 ** 9 + 7 dp = np.zeros(9, dtype=np.int64) dp[0] = 1 zero_flag = True for t in T: if t == '?': dp += np.full(9, dp.sum()) dp %= MOD else: t = int(t) if t: zero_flag = False dp = np.roll(dp, t) if zero_flag: dp[8] -= 1 if D: D %= 9 ans = dp[D] else: ans = 1 else: if D: D %= 9 ans = dp[D] else: ans = 0 print(ans)