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 coef=0 for i in range(cnt): coef+=pow(10,i,mod) coef%=mod coef=[1]+[coef]*9 ans=0 if tmp==d: ans+=1 for i in range(1,10): if (tmp+i-d)%9==0: ans+=coef[i] ans%=mod print(ans%mod) if d==0: if tmp!=0: print(0) else: print(1)