from sys import stdin, stdout

from collections import deque, defaultdict

from functools import lru_cache



rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))



INF, NINF = float('inf'), float('-inf')



def main():

	MOD = 10**9 + 7

	x = []

	for c in rll()[0]:

		x.append(int(c))

	d = int(rl())

	ans = 0



	dp = [[0 for __ in range(2)] for _ in range(d)]

	dp[0][1] = 1

	for i in range(len(x)):

		ndp = [[0 for __ in range(2)] for _ in range(d)]

		for digsum in range(d):

			for tight in range(2):

				for nd in range(x[i]+1 if tight else 10):

					ns = (digsum + nd) % d 

					ntight = 1 if tight and nd == x[i] else 0

					ndp[ns][ntight] += dp[digsum][tight]

					ndp[ns][ntight] %= MOD

		dp = ndp



	ans = (dp[0][0] + dp[0][1] - 1) % MOD

	print(ans)

	stdout.close()



if __name__ == "__main__":

	main()
from sys import stdin, stdout, setrecursionlimit

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from functools import lru_cache

import math



setrecursionlimit(10**6)

rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))

rlf = lambda: list(map(float, stdin.readline().split()))



INF, NINF = float('inf'), float('-inf')

MOD = 10**9 + 7



def main():

	K = rll()[0]

	D = int(rl())

	lim = []

	for c in K: lim.append(int(c))

	n = len(lim)

	dp = [[[0]*D for j in range(2)] for i in range(n+1)]

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

	for i in range(n):

		for tight in range(2):

			for ds in range(D):

				md = lim[i] if tight else 9

				for d in range(md+1):

					nt = 1 if tight and lim[i] == d else 0

					nds = (d + ds) % D

					dp[i+1][nt][nds] += dp[i][tight][ds]

					dp[i+1][nt][nds] %= MOD

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

	print(ans)

	stdout.close()



if __name__ == "__main__":

	main()
from sys import stdin, stdout
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")


def main():
    MOD = 10**9 + 7
    x = []
    for c in rll()[0]:
        x.append(int(c))
    d = int(rl())
    ans = 0
    dp = [[0 for __ in range(2)] for _ in range(d)]
    dp[0][1] = 1
    for i in range(len(x)):
        ndp = [[0 for __ in range(2)] for _ in range(d)]
        for digsum in range(d):
            for tight in range(2):
                for nd in range(x[i] + 1 if tight else 10):
                    ns = (digsum + nd) % d
                    ntight = 1 if tight and nd == x[i] else 0
                    ndp[ns][ntight] += dp[digsum][tight]
                    ndp[ns][ntight] %= MOD
        dp = ndp
    ans = (dp[0][0] + dp[0][1] - 1) % MOD
    print(ans)
    stdout.close()


if __name__ == "__main__":
    main()

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7


def main():
    K = rll()[0]
    D = int(rl())
    lim = []
    for c in K:
        lim.append(int(c))
    n = len(lim)
    dp = [[[0] * D for j in range(2)] for i in range(n + 1)]
    dp[0][1][0] = 1
    for i in range(n):
        for tight in range(2):
            for ds in range(D):
                md = lim[i] if tight else 9
                for d in range(md + 1):
                    nt = 1 if tight and lim[i] == d else 0
                    nds = (d + ds) % D
                    dp[i + 1][nt][nds] += dp[i][tight][ds]
                    dp[i + 1][nt][nds] %= MOD
    ans = (dp[n][0][0] + dp[n][1][0] - 1) % MOD
    print(ans)
    stdout.close()


if __name__ == "__main__":
    main()

-from sys import stdin, stdout -from collections import deque, defaultdict +from sys import stdin, stdout, setrecursionlimit +from collections import deque, defaultdict, Counter +from heapq import heappush, heappop +import math +setrecursionlimit(10**6) +rlf = lambda: list(map(float, stdin.readline().split())) +MOD = 10**9 + 7 -    MOD = 10**9 + 7 -    x = [] -    for c in rll()[0]: -        x.append(int(c)) -    d = int(rl()) -    ans = 0 -    dp = [[0 for __ in range(2)] for _ in range(d)] -    dp[0][1] = 1 -    for i in range(len(x)): -        ndp = [[0 for __ in range(2)] for _ in range(d)] -        for digsum in range(d): -            for tight in range(2): -                for nd in range(x[i] + 1 if tight else 10): -                    ns = (digsum + nd) % d -                    ntight = 1 if tight and nd == x[i] else 0 -                    ndp[ns][ntight] += dp[digsum][tight] -                    ndp[ns][ntight] %= MOD -        dp = ndp -    ans = (dp[0][0] + dp[0][1] - 1) % MOD +    K = rll()[0] +    D = int(rl()) +    lim = [] +    for c in K: +        lim.append(int(c)) +    n = len(lim) +    dp = [[[0] * D for j in range(2)] for i in range(n + 1)] +    dp[0][1][0] = 1 +    for i in range(n): +        for tight in range(2): +            for ds in range(D): +                md = lim[i] if tight else 9 +                for d in range(md + 1): +                    nt = 1 if tight and lim[i] == d else 0 +                    nds = (d + ds) % D +                    dp[i + 1][nt][nds] += dp[i][tight][ds] +                    dp[i + 1][nt][nds] %= MOD +    ans = (dp[n][0][0] + dp[n][1][0] - 1) % MOD