N = int(input()) // 1000 M = int(input()) mod = N % M if mod == 0: print(1) exit() MOD = 10 ** 9 + 7 fact = [1]*(M+1) rfact = [1]*(M+1) r = 1 for i in range(1, M+1): fact[i] = r = r * i % MOD rfact[M] = r = pow(fact[M], -1, MOD) for i in range(M, 0, -1): rfact[i-1] = r = r * i % MOD # nCk (mod MOD) を求める def comb(n, k): return fact[n] * rfact[k] * rfact[n-k] % MOD print(comb(M,mod) % 10 ** 9)