import sys input = sys.stdin.readline T = input()[:-1] N = len(T) D = int(input()) flag = True for i in range(N): if T[i]!='?' and T[i]!='0': flag = False if D==0: if flag: print(1) else: print(0) exit() dp = [[0]*9 for _ in range(N+1)] dp[0][0] = 1 MOD = 10**9+7 for i in range(N): if T[i]!='?': for j in range(9): k = (j+int(T[i]))%9 dp[i+1][k] += dp[i][j] dp[i+1][k] %= MOD else: for j in range(9): for k in range(10): l = (j+k)%9 dp[i+1][l] += dp[i][j] dp[i+1][l] %= MOD if D==9: if flag: print((dp[N][0]-1)%MOD) else: print(dp[N][0]) else: print(dp[N][D])