#include #define ll long long #define INF 1000000005 #define MOD 1000000000 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<P; const int MAX_N = 10005; ll comb[2][MAX_N]; void make(int N){ for(int i=1;i<=N;i++){ comb[0][0] = 1; for(int j=1;j<=i;j++){ comb[1][j] = (comb[0][j] + comb[0][j-1]) % MOD; } swap(comb[0],comb[1]); } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; int mod; cin >> mod; ll K = (n / 1000) % mod; make(mod); cout << comb[0][K] << endl; return 0; }