from math import factorial N = int(input()) M = int(input()) x = N // 1000 % M print((factorial(M) // factorial(x) // factorial(M - x)) % (10 ** 9))