T=input() D=int(input()) N=len(T) mod=10**9+7 if D==0: for i in range(N): if T[i]!="0" and T[i]!="?": print(0) break else: print(1) else: dp=[[0 for i in range(9)] for j in range(N)] if T[0]=="?": for j in range(10): dp[0][j%9]+=1 else: dp[0][int(T[0])%9]=1 for i in range(1,N): for j in range(9): if T[i]=="?": for k in range(10): dp[i][(j+k)%9]+=dp[i-1][j] dp[i][(j+k)%9]%=mod else: dp[i][(j+int(T[i]))%9]+=dp[i-1][j] dp[i][(j+int(T[i]))%9]%=mod print(dp[-1][D%9])