import bisect
import copy
import decimal
import fractions
import functools
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines

def Power(x,n,f,e):
    if n==0:
        return e
    s=e
    double=x
    while n>=2:
        if n&1:
            s=f(s,double)
        double=f(double,double)
        n>>=1
    s=f(s,double)
    return s

S=readline().rstrip()
D=int(readline())
if D==0:
    for s in S:
        if not s in "0?":
            ans=0
            break
    else:
        ans=1
else:
    D%=9
    cnt=0
    su=D
    mod=10**9+7
    for s in S:
        if s=="?":
            cnt+=1
        else:
            su-=int(s)
    su%=9
    def f(poly0,poly1):
        poly=[0]*9
        for i in range(9):
            for j in range(9):
                poly[(i+j)%9]+=poly0[i]*poly1[j]
                poly[(i+j)%9]%=mod
        return poly
    e=[0]*9
    e[0]=1
    x=[1]*9
    x[0]=2
    ans=Power(x,cnt,f,e)[su]
    if D==0:
        for s in S:
            if not s in "0?":
                break
        else:
            ans-=1
            ans%=mod
print(ans)