import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

    k=eval(input())

    d=int(eval(input()))

    n=len(k)

    dp=[[[0]*2 for _ in range(d)] for _ in range(n+1)]

    dp[0][0][0]=1

    for i in range(n):

        a=int(k[i])

        for j in range(d):

            for o in range(10):

                dp[i+1][(j+o)%d][1]+=dp[i][j][1]

                dp[i+1][(j+o)%d][1]%=MOD

                if(o<a):

                    dp[i+1][(j+o)%d][1]+=dp[i][j][0]

                    dp[i+1][(j+o)%d][1]%=MOD

                elif(o==a):

                    dp[i+1][(j+o)%d][0]+=dp[i][j][0]

                    dp[i+1][(j+o)%d][0]%=MOD

    print(((dp[n][0][0]+dp[n][0][1]-1)%MOD))

resolve()

import sys

sys.setrecursionlimit(2147483647)

INF = float("inf")

MOD = 10**9 + 7 # 998244353

input = lambda:sys.stdin.readline().rstrip()

from itertools import product

def resolve():

    k = eval(input())

    modulo = int(eval(input()))

    dp = [[0] * 2 for _ in range(modulo)]

    dp[0][0] = 1



    for d in k:

        d = int(d)

        ndp = [[0] * 2 for _ in range(modulo)]

        for r, lt in product(list(range(modulo)), list(range(2))):

            for x in range(10):

                if (not lt) and x > d:

                    continue

                nlt = max(lt, x < d)

                nr = (r + x) % modulo

                ndp[nr][nlt] += dp[r][lt]

                if ndp[nr][nlt] >= MOD:

                    ndp[nr][nlt] -= MOD

        dp = ndp



    print(((dp[0][0] + dp[0][1] - 1) % MOD))

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    k = eval(input())
    d = int(eval(input()))
    n = len(k)
    dp = [[[0] * 2 for _ in range(d)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(n):
        a = int(k[i])
        for j in range(d):
            for o in range(10):
                dp[i + 1][(j + o) % d][1] += dp[i][j][1]
                dp[i + 1][(j + o) % d][1] %= MOD
                if o < a:
                    dp[i + 1][(j + o) % d][1] += dp[i][j][0]
                    dp[i + 1][(j + o) % d][1] %= MOD
                elif o == a:
                    dp[i + 1][(j + o) % d][0] += dp[i][j][0]
                    dp[i + 1][(j + o) % d][0] %= MOD
    print(((dp[n][0][0] + dp[n][0][1] - 1) % MOD))


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7  # 998244353
input = lambda: sys.stdin.readline().rstrip()
from itertools import product


def resolve():
    k = eval(input())
    modulo = int(eval(input()))
    dp = [[0] * 2 for _ in range(modulo)]
    dp[0][0] = 1
    for d in k:
        d = int(d)
        ndp = [[0] * 2 for _ in range(modulo)]
        for r, lt in product(list(range(modulo)), list(range(2))):
            for x in range(10):
                if (not lt) and x > d:
                    continue
                nlt = max(lt, x < d)
                nr = (r + x) % modulo
                ndp[nr][nlt] += dp[r][lt]
                if ndp[nr][nlt] >= MOD:
                    ndp[nr][nlt] -= MOD
        dp = ndp
    print(((dp[0][0] + dp[0][1] - 1) % MOD))


resolve()

-MOD = 10**9 + 7 +MOD = 10**9 + 7  # 998244353 +from itertools import product -    d = int(eval(input())) -    n = len(k) -    dp = [[[0] * 2 for _ in range(d)] for _ in range(n + 1)] -    dp[0][0][0] = 1 -    for i in range(n): -        a = int(k[i]) -        for j in range(d): -            for o in range(10): -                dp[i + 1][(j + o) % d][1] += dp[i][j][1] -                dp[i + 1][(j + o) % d][1] %= MOD -                if o < a: -                    dp[i + 1][(j + o) % d][1] += dp[i][j][0] -                    dp[i + 1][(j + o) % d][1] %= MOD -                elif o == a: -                    dp[i + 1][(j + o) % d][0] += dp[i][j][0] -                    dp[i + 1][(j + o) % d][0] %= MOD -    print(((dp[n][0][0] + dp[n][0][1] - 1) % MOD)) +    modulo = int(eval(input())) +    dp = [[0] * 2 for _ in range(modulo)] +    dp[0][0] = 1 +    for d in k: +        d = int(d) +        ndp = [[0] * 2 for _ in range(modulo)] +        for r, lt in product(list(range(modulo)), list(range(2))): +            for x in range(10): +                if (not lt) and x > d: +                    continue +                nlt = max(lt, x < d) +                nr = (r + x) % modulo +                ndp[nr][nlt] += dp[r][lt] +                if ndp[nr][nlt] >= MOD: +                    ndp[nr][nlt] -= MOD +        dp = ndp +    print(((dp[0][0] + dp[0][1] - 1) % MOD))