s = input() m = int(input()) MOD = 10**9+7 dp = [0]*m dp[0] = 1 for i in s: i = int(i) ndp = dp[:] for j in range(m): nj = (j*10+i)%m ndp[nj] += dp[j] ndp[nj] %= MOD if i == 0: ndp[0] -= 1 dp = ndp print((dp[0]+s.count("0")-1)%MOD)