#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const LL mod = (LL)1e9;
const int maxC = 10000;
LL c[maxC][maxC/2];

LL ccc(LL n,LL k){
	LL ans;
	LL kk = min(k,n-k);
	if(n<maxC && kk < maxC && c[n][kk] != 0){
		ans = c[n][kk];
	}
	else if(kk ==0 ){
		if(n<maxC){
			c[n][kk] = 1;
		}
		ans = 1;
	}else if( kk==1){
		if(n<maxC){
			c[n][kk] = n%mod;
		}
		ans = n%mod;
	}
	else{
		ans = (ccc(n-1,kk-1)%mod+ccc(n-1,kk)%mod)%mod;
		if(n<maxC && kk < maxC){
			c[n][kk] = ans;
		}
	}

	return ans;
}
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
    
	LL N,M;
	cin>>N>>M;
	LL ama = (N%(M*1000))/1000;
	//rep(i,maxC)rep(j,maxC)c[i][j]=-1;
	//N C ama
	P(ccc(M,ama));
    return 0;
}