import numpy as np S = input() M = int(input()) MOD = 10 ** 9 + 7 dp = np.zeros(M, dtype=int) ans = 0 for s in S: s = int(s) np.add.at(dp, np.arange(s, s + 10 * M, 10) % M, dp) if s: dp[s % M] += 1 else: ans += 1 dp %= MOD print((dp[0] + ans) % MOD)