def comb(m, n): global mod n = min(n, m - n) ans = 1 for i in range(n): ans *= (m - i) for i in range(n,1,-1): ans //= i return ans % mod N = int(input()) M = int(input()) mod = 1000000000 num = (N//1000) % M ans = comb(M, num) print(ans)