#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
#define dbg(x) cerr<<#x": "<<(x)<<'\n'
#define dbg_v(x, n) cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<'\n'
#define all(v) v.begin(), v.end()
#define MOD 666013
#define NMAX 100010

int fact[NMAX];

int power(int base, int exp)
{
	int res;
	for(res = 1; exp; exp >>= 1)
	{
		if(exp & 1) res = (1LL * res * base) % MOD;
		base = (1LL * base * base) % MOD;
	}

	return res;
}

int inv_mod(int x)
{
	return power(x, MOD - 2);
}

int comb(int n, int k)
{
	int x = (1LL * fact[n] * inv_mod(fact[k])) % MOD;
	return (1LL * x * inv_mod(fact[n - k])) % MOD;
}

int main()
{
#ifndef ONLINE_JUDGE
	ifstream cin("data.in");
	ofstream cout("data.out");
#endif
	ios_base::sync_with_stdio(false);

	int i, n, m, t1, t2, ter, sign;

	for(fact[0] = 1, i = 1; i < NMAX; ++i)
		fact[i] = (1LL * fact[i - 1] * i) % MOD;

	cin >> n >> m;

	if(n < m) return cout << 0 << '\n', 0;

	for(t1 = 0, ter = 1, sign = (m & 1 ? -1 : 1), i = m; i >= 2; --i)
	{
		t1 += sign * ter;
		if(t1 < 0) t1 += MOD;
		if(t1 >= MOD) t1 -= MOD;

		sign = -sign;
		ter = (1LL * ter * i) % MOD;
	}

	for(t2 = 0, sign = 1, i = 1; i <= m; ++i)
	{
		t2 += (1LL * sign * comb(m, i) * power(m - i, n)) % MOD;
		if(t2 >= MOD) t2 -= MOD;
		sign = -sign;
	}

	t2 = power(m, n) - t2;
	if(t2 < 0) t2 += MOD;

	cout << ((1LL * t1 * t2) % MOD) << '\n';

	return 0;
}