N = int(input()) M = int(input()) total = 1000 * M k = N // total R = N - k * total t = R // 1000 if t == 0: print(1) else: mod = 10**9 res = 1 for i in range(t): res = res * (M - i) // (i + 1) print(res % mod)