// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
#define MOD 1000000000
map<ll,ll> dv(ll n){
  map<ll,ll> mp;
  for(ll i=2;i*i<=n;i++){
    ll cnt = 0;
    while(n%i==0){
      n/=i;
      cnt++;
    }
    if(cnt>0){
      mp[i]+=cnt;
    }
  }
  if(n!=1) mp[n]++;
  return mp;
}
long long pmod(long long x, long long n) {
  if(n==0) return 1;
  if(n%2==0){
    ll v = pmod(x,n/2);
    v*=v; v %= MOD;
    return v;
  }
  return (x*pmod(x,n-1))%MOD;
}
ll cmb(ll n,ll r){
  map<ll,ll> mp;
  ll res=1;
  for(ll i=1;i<=r;i++){
    map<ll,ll> t0=dv(n+1-i),t1=dv(i);
    for(auto p:t0){
      mp[p.first]+=p.second;
    }
    for(auto p:t1){
      mp[p.first]-=p.second;
    }
  }
  for(auto p:mp){
    res *= pmod(p.first,p.second);
    res %= MOD;
  }
  return res;
}
signed main(){
  init_io();
  ll n,m;
  cin >> n >> m;
  n /= 1000;
  n -= (n/m)*m;
  cout << cmb(m,n)<<endl;
}