import math N = int(input()) M = int(input()) def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) def floor(src, p=1000): return int(src / p) * p a, b = divmod(N, 1000*M) surplus = floor(b) ans = ncr(M, surplus//1000) print(ans%1000000000)