#include using namespace std; const long long kMod = 1000000000; long long CalcCombination(int n, int r) { int** dp = new int*[n + 1]; for (int i = 0; i < n + 1; i++) { dp[i] = new int[i + 1]; for (int j = 0; j < i + 1; j++) { if (j == 0 || j == i) { dp[i][j] = 1; } else { dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % kMod; } } } return dp[n][r]; } int main() { int n, m; cin >> n >> m; int r = (n / 1000) % m; cout << CalcCombination(m, r) << endl; return 0; }