def factorial(x): retval = 1 for i in range(2,x+1): retval = retval * i return retval def nCr(n,r): return factorial(n)/ factorial(n-r)/factorial(r) %10**9 n = int(input()) m = int(input()) rest = (n%(1000*m)) print nCr(m,(rest - (rest%1000))/1000)