def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 T=input() D=I() N=len(T) if D==0: S=0 cnt=0 for i in range(N): if T[i]=="?": cnt+=1 else: S+=int(T[i]) if S==0: print(1) else: print(0) exit() dp=[[0]*9 for _ in range(N+1)] #dp[i][j]はi番目まで見て桁和の桁和がj dp[0][0]=1 for i in range(N): t=T[i] if t=="?": for j in range(9): dp[i][j]=dp[i][j]%mod for k in range(10):#?をkにする dp[i+1][(j+k)%9]+=dp[i][j] else: t=int(t) for j in range(9): dp[i][j]=dp[i][j]%mod dp[i+1][(j+t)%9]=dp[i][j] print(dp[-1][D%9]%mod) main()