#include <iostream>
#include <vector>
#define mod 1020847

int n,p;
std::vector< std::vector<long> > F;
std::vector< std::vector<bool> > calced;

long fact(int k) {
     long res = 1;
     for(int i=2;i<=k;i++) {
             res*=i;
             res%=mod;
     }
     return res;
}
long dp(int n,int p) {
     if(calced[n][p]) return F[n][p];
     if(n == 0 && p == 0) return 1;
     if(p == 1) {
          calced[n][p] = 1;
          return (F[n][p] = fact(n-1));
     }
     if(n == p) {
          calced[n][p] = 1;
          return (F[n][p] = n);
     }
     if(n == 0) return 0;
     calced[n][p] = 1;
     F[n][p] = (dp(n-1,p-1) + dp(n-1,p)) % mod;
     return F[n][p];
}
int main() {
    std::cin >> n >> p;
    F.resize(n+2); calced.resize(n+2);
    for(int i=0;i<n+2;i++) { F[i].resize(n+2); calced[i].resize(n+2,0); }
    std::cout << dp(n,p) << std::endl;
    return 0;
}
