import java.util.Scanner; public class Main { public static void main(String[] args) { solver(); } final static long MOD = 1_000_000_007; static long[] fact; static void solver() { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); long[] dp = new long[m + 1]; fact = new long[m + 1]; fact[0] = 1; fact[1] = 1; dp[1] = 1; for (int i = 2; i <= m; i++) { fact[i] = fact[i - 1] * (i % MOD) % MOD; } for (int i = 2; i <= m; i++) { dp[i] = pow(i, n); for (int j = 1; j < i; j++) { dp[i] -= nCk(i, j) * dp[j] % MOD; if (dp[i] < 0) dp[i] += MOD; dp[i] %= MOD; } } System.out.println(dp[m]); } 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; } static long nCk(int n, int k) { if (n < k) return 0; else { return (fact[n] * inv(fact[n - k], MOD) % MOD * inv(fact[k], MOD)) % MOD; } } 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; } }