from math import * from collections import * def Sieve(n): lst = [True] * (n + 1) S = set() for i in range(2, ceil(sqrt(n)) + 1): if lst[i]: for j in range(2 * i, n + 1, i): lst[j] = False for i in range(2, n + 1): if lst[i]: S.add(i) return S N = int(input())//1000 M = int(input()) r = N % M ans = 1 mod = 10 ** 9 inv = 1 seen = [0] * (r + 1) P = Sieve(M) D = defaultdict(int) for p in P: now = p while True: D[p] += r//now now *= p if M // now == 0: break for i in range(r): now = M - i for k, v in D.items(): while D[k]: if now % k == 0: now //= k D[k] -= 1 else: break ans *= now ans %= mod print(ans)