package no391; import java.util.Scanner; public class Main { /* * 問題への割り当てf(x) * 異なる全射の数え上げ * ググった * http://mathtrain.jp/zensya */ public static long MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); if (n < m) { throw new RuntimeException("反則"); } long ans = 0; long[] fact = Mod.factorialArray(m+1, MOD); long[] factInv = Mod.factorialInverseArray(m+1, MOD, Mod.inverseArray(m+1, MOD)); for(int i=1;i<=m;i++) { long x = fact[m] * factInv[i] % MOD * factInv[m-i] % MOD * Mod.pow(i, n, MOD); ans = Mod.n(ans + ((m - i) % 2 == 0 ? 1 : -1) * x, MOD); } System.out.println(ans); } } class Mod { public static long n(long x,long mod) { x %= mod; if (x < 0) { x += mod; } return x; } public static long pow(long a,long n,long mod) { long res = 1; while(n > 0) { if ((n & 1) > 0) { res = (res * a) % mod; } a = (a * a) % mod; n/=2; } return res; } public static long[] inverseArray(int maxN,long modP) { long[] inv = new long[maxN+1]; inv[1] = 1; for(int i=2;i<=maxN;i++) { inv[i] = modP - (modP / i) * inv[(int) (modP%i)] % modP; } return inv; } public static long[] factorialArray(int maxN,long mod) { long[] fact = new long[maxN+1]; fact[0] = 1 % mod; for(int i=1;i<=maxN;i++) { fact[i] = fact[i-1] * i % mod; } return fact; } public static long[] factorialInverseArray(int maxN,long modP,long[] inverseArray) { long[] factInv = new long[maxN+1]; factInv[0] = 1; for(int i=1;i<=maxN;i++) { factInv[i] = factInv[i-1] * inverseArray[i] % modP; } return factInv; } }