// yukicoder: No.391 CODING WAR // 2019.5.8 bal4u #include typedef long long ll; #define MOD 1000000007 #define MAX 100000 int fact[MAX+2], inv[MAX+2], factinv[MAX+2]; int comb(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; if (k == 0) return 1; return ((((ll)fact[n] * factinv[k]) % MOD) * factinv[n-k]) % MOD; } int modpow(int x, long long p) { int r = 1; while (p) { if (p & 1) r = (ll)r * x % MOD; x = (ll)x * x % MOD; p >>= 1; } return r; } int main() { int M, i, a; ll N, ans; fact[0] = 1; for (i = 1; i <= MAX; i++) fact[i] = ((ll)fact[i-1]*i) % MOD; inv[1] = 1; for (i = 2; i <= MAX; i++) inv[i] = (MOD + (-(MOD/i)*(ll)inv[MOD % i]) % MOD) % MOD; factinv[0] = 1; for (i = 1; i <= MAX; i++) factinv[i] = ((ll)factinv[i-1]*inv[i]) % MOD; scanf("%lld%d", &N, &M); if (N < M) ans = 0; else { int sign = (M & 1); ans = 0; for (i = 1; i <= M; i++) { a = ((ll)modpow(i, N) * comb(M, i)) % MOD; if (sign) ans += a; else ans -= a; sign = !sign; } } ans %= MOD; if (ans < MOD) ans += MOD; printf("%d\n", (int)ans); return 0; }