package No300台; import java.util.Scanner; public class Main { public static void main(String[] args) { solver(); } static final long MOD = 1_000_000_007; static long[] fact; static long[] inv_fact; static void solver() { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); fact = new long[m + 1]; inv_fact = new long[m + 1]; fact[0] = 1; fact[1] = 1; for (int i = 2; i <= m; i++) { fact[i] = fact[i - 1] * (i % MOD) % MOD; } long ans = 0; for (int i = 0; i <= m - 1; i++) { ans+=nCk(m, i) * pow(m - i, n) % MOD * (i % 2 == 0 ? 1 : -1); if (ans < 0) ans += MOD; ans %= MOD; } System.out.println(ans); } static long nCk(int n, int k) { if (n < k) return 0; else { if (inv_fact[n - k] == 0) inv_fact[n - k] = inv(fact[n - k], MOD); if (inv_fact[k] == 0) inv_fact[k] = inv(fact[k], MOD); return fact[n] * inv_fact[n - k] % MOD * inv_fact[k] % MOD; } } static long fact(int n) { long ans = 1; for (int i = 1; i <= n; i++) ans *= i; return ans; } static long pow(long a, long n) { long A = a; long ans = 1; while (n >= 1) { if (n % 2 == 0) { A = (A * A) % MOD; n /= 2; } else if (n % 2 == 1) { ans = ans * A % MOD; n--; } } return ans; } static long inv(long a, long mod) { a = a % mod; long b = mod; long p = 1, q = 0; while (b > 1) { long c = b / a; b = b % a; q = q - p * c; long d = b; b = a; a = d; d = p; p = q; q = d; } while (q < 0) q += mod; return q; } }