import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int length = arr.length; int m = sc.nextInt(); long ans = 0; int[] prev = new int[m]; int[] next = new int[m]; for (int i = 0; i < length; i++) { int x = arr[i] - '0'; for (int j = 0; j < m; j++) { next[j] += prev[j]; next[j] %= MOD; next[(j * 10 + x) % m] += prev[j]; next[(j * 10 + x) % m] %= MOD; } if (x == 0) { ans++; } else { next[x % m]++; } int[] tmp = next; next = prev; prev = tmp; Arrays.fill(next, 0); } System.out.println((prev[0] + ans) % MOD); } }