#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2005,Mod=1e9+7;
int dp[N][N],fac[N*N],inv[N*N];
inline int C(int n,int m){
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
int main (){
	int n,k;scanf ("%d%d",&n,&k);
	if (k==1) {puts("1");return 0;}
	dp[0][0]=1;fac[0]=1;
	for (int i=1;i<=n*k;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[n*k]=qpow(fac[n*k],Mod-2);for (int i=n*k-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
    for (int i=0;i<=n;i++) dp[i][0]=1;
	for (int i=1;i<=n;i++)
        for (int j=0;j<=i;j++)
            dp[i][j]=dp[i-1][j]+1ll*dp[i][j-1]*(n-j+1)%Mod*C(n*k-(i+(j-1)*(k-1))-1,k-2)%Mod,dp[i][j]%=Mod;
    printf ("%d",dp[n][n]);
	return 0;
}
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;
string a;
int d,n,mod=1e9+7;

int digitSum(int idx,int sum,bool tight,vector<vector<int> > &dp){
	if(idx==n)
		return sum==0?1:0;
	if(!tight&&dp[n-idx-1][sum]!=-1)
		return dp[n-idx-1][sum];
	int ans =0;
	int k = tight?a[idx]-48:10;
	for(int i=0;i<k;i++)
		ans = (digitSum(idx+1,(sum+i)%d,0,dp)+ans)%mod;
	if(tight){
		ans = (digitSum(idx+1,(sum+k)%d,1,dp)+ans)%mod;
	} else {
		dp[n-idx-1][sum] = ans;
	}
	return ans;
}

int main()
{	
	cin >> a >> d;
	n = a.size();
	vector<vector<int> > dp(n,vector<int>(d,-1));
	cout << (digitSum(0,0,1,dp)-1+mod)%mod;
    return 0;
}