def comb(n, r): res = 1 for i in range(int(r)): res *= n n -= 1 res //= (i + 1) return res N = input() M = input() N //= int(1e3) N %= M print comb(M, N) % int(1e9)