N = int(input()) M = int(input()) MOD = 10**9 N = N//1000 r = N%M dp = [[0 for _ in range(r+1)] for _ in range(2)] dp[0][0] = 1 dp[1][0] = 1 for i in range(1,M+1): for j in range(1,r+1): if j>i:break dp[i%2][j] = (dp[(i-1)%2][j]+dp[(i-1)%2][j-1])%MOD print(dp[M%2][r])