//	Mohib Manva
#include<bits/stdc++.h>
using namespace std;

#define mod 666013 
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	if(a==0){
		return 0;
	}
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

static ll f[200005],inv[200005];


ll nCr(int n,int r){
	if(r<-1 || n<r)
		return 0;
	if(r==-1)
		return 1;
	ll ans = f[n];
	ans = (ans*inv[r])%mod;
	ans = (ans*inv[n-r])%mod;
	return ans;
}

int main(){
	f[0] = inv[0] = 1ll;
	for(int i=1;i<=200000;i++){
		f[i] = (f[i-1]*i)%mod;
		inv[i] = po(f[i],mod-2);
	}
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d %d",&n,&m);
		if(n<m){
			puts("0");
		} else {
			int n1 = n;
			ll ans1 = po(m,n);
			for(int i=1;i<=m;i++){
				if(i%2){
					ll tmp = (nCr(m,i)*po(m-i,n))%mod;
					ans1 = (ans1 - tmp + mod)%mod;
				} else {
					ll tmp = (nCr(m,i)*po(m-i,n))%mod;
					ans1 = (ans1+tmp)%mod;
				}
			}
			ll tot = f[m];
			ll exclude = 0ll;
			for(int i=1;i<=m;i++){
				if(i%2){
					exclude += (nCr(m,i)*f[m-i])%mod;
					exclude %= mod;
				} else {
					exclude = (exclude - (nCr(m,i)*f[m-i])%mod + mod)%mod;
				}
			}
			tot = (tot-exclude+mod)%mod;
		//	printf("%lld %lld\n",tot,exclude);
			printf("%lld\n",(ans1*tot)%mod);
		}
	}
	return 0;	
}