T=input() N=len(T) D=int(input()) mod=10**9+7 if D==0: for i in range(N): if T[i]!='0' and T[i]!='?': print(0) exit() print(1) exit() if set(T)==set([0]): print(0) exit() DP=[[0]*9 for i in range(N+1)] DP[0][0]=1 x=0 for i in range(N): if T[i]=='?': x=sum(DP[i])%mod for j in range(9): DP[i+1][j]=(x+DP[i][j])%mod else: for j in range(9): DP[i+1][(j+int(T[i]))%9]=DP[i][j] if D==9 and set(T)=={'0','?'}: DP[N][D%9]=(DP[N][D%9]-1)%mod print(DP[N][D%9])