#include <cstdlib>
#include <cstdio>

int N, P;
int opt[2000][2000];
int comb[2000][2000];
int fact[2000];
const int MOD = 1020847;


void fill_comb () {
     comb[0][0] = comb[1][0] = comb[1][1] = 1;

     for (int i = 2; i <= N; ++i) {
         comb[i][0] = 1;
         for (int j = 1; j <= i; ++j) {
             comb [i][j] = comb[i-1][j] + comb[i-1][j-1];
             comb [i][j] %= MOD;
         }
     }

     fact[0] = fact[1] = 1;
     for (int i = 2; i <= N; ++i)
         fact[i] = ((long long)i*fact[i-1]) % MOD;
}


int f (int n, int p) {
//    printf ("%d %d\n", n, p);
    if (opt[n][p])
       return opt[n][p];

    if (p == 1)
       return opt[n][1] = fact[n-1];

    if (n == p)
       return opt[n][n] = 1;
    int ret = 0;
    int np = n-p;
    n--;
    p--;
    for (int i = 0; i <= np; ++i)
        ret += (long long)comb[n][i] * f (n - i, p) % MOD;


    return opt[n+1][p+1] = ret;
}


int main () {
    scanf ("%d%d", &N, &P);

    fill_comb ();
//    f (N, P);
/*    for (int i = 0; i < 20; ++i) {
        for (int j = 0; j < 20; ++j)
            printf ("%d ", opt[i][j]);
        printf ("\n");
    }
    system ("PAUSE");

    for (int i = 0; i < 20; ++i) {
        printf ("%d ", fact[i]);
    }
    system ("PAUSE");
*/
    printf ("%d\n", f (N, P));
//    system ("PAUSE");

    return 0;
}
