#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; int C[10001][10001]; long long func( int n, int r ) { if ( n/2 < r ) { r = n-r; } if ( r == 0 ) { return 1; } if ( C[n][r] > 0 ) { return C[n][r]; } C[n][r] = ( func( n-1, r ) + func( n-1, r-1 ) ) % ( (long long)1e9 ); return C[n][r]; } int main() { long long N,M; cin >> N >> M; int a = (N/1000)%M; long long ans = func( M, a ); cout << ans << endl; return 0; }