#include <iostream>

using namespace std;

const unsigned long long MOD = 1020847;

unsigned long long int n, p;
unsigned long long F[ 2048 ];
unsigned long long nF[ 2048 ];

int main( )
{
 cin >> n >> p;
 int i, j;

 for ( i=2; i<=n; i++ )
	F[ i ] = 0;
 F[ 0 ] = 0;
 F[ 1 ] = 1;

 for ( i=2; i<=n; i++ )
 {
  	for( j=1; j<=i; j++ )
   {
		if ( i == j )
   		nF[ j ] = 1;
		else
      	nF[ j ] = ( ( ( ( (i-1)*F[ j ])%MOD ) + F[ j-1 ] ) % MOD );
   }

 	memcpy( F, nF, sizeof( nF ) );
 }

 cout << nF[ p ] << endl;

 return 0;
}
