def seachPrimeNum(N): max = int(N**0.5) seachList = [i for i in range(2,N+1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum def adic(dic,x): if x in dic: dic[x] += 1 else: dic[x] = 1 return def factorization(x): dic = {} for p in PL: if x in PL: adic(dic,x) return dic while x % p == 0: adic(dic,p) x //= p if x == 1: return dic MOD = 10 ** 9 N = int(input()) // 1000 M = int(input()) mod = N % M if mod == 0: print(1) exit() PL = seachPrimeNum(M) PL = set(PL) def comb(n, m): dic = {} ret = 1 for i in range(m): F = factorization(i + 1) for k,v in F.items(): if k in dic: dic[k] += v else: dic[k] = v for i in range(m): F = factorization(n - i) for k,v in F.items(): if k in dic: if dic[k] >= v: dic[k] -= v v = 0 else: v -= dic[k] dic.pop(k) ret *= k ** v ret %= MOD return ret print(comb(M,mod))