mod=10**9+7 t=input() d=int(input()) tmp=0 cnt=0 for c in t: if c=='?': cnt+=1 else: tmp+=int(c) if d!=0: if tmp!=0 and tmp%9==0: tmp=9 else: tmp%=9 coef=0 for i in range(cnt): coef+=pow(10,i,mod) coef%=mod if tmp==0: ans=coef elif tmp==d: ans=coef+1 else: ans=coef print(ans%mod) if d==0: if tmp!=0: print(0) else: print(1)