#include<stdlib.h>
#include<stdio.h>
unsigned long a[2010][2010];

unsigned long f(int n,int p)
{
 if(n==p)return 1;
// if(a[n][p]!=0 && n<120)return a[n][p];
 if(p==1){int i;unsigned long sum=1;for(i=1;i<n;i++)sum=sum*i;return sum;}
 a[n][p]=f(n-1,p)*(n-1)+f(n-1,p-1);
 return a[n][p];
}
int main()
{
int n,p;
unsigned long res;
scanf("%d %d",&n,&p);
res=f(n,p);
res=res%1020847;
char *q;
//q=new char[30];
//itoa(res,q,10);
printf("%D\n",res);
return 0;
}



