INF = 10 ** 9 MOD = 10 **9 + 7 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from collections import deque from math import factorial MAXN = 100005 factorial = [1] for i in range(1, MAXN + 1): factorial.append(factorial[-1] * i % MOD) inv_factorial = [-1] * (MAXN + 1) inv_factorial[-1] = pow(factorial[-1], MOD-2, MOD) for i in reversed(range(MAXN)): inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD def fact(n): return factorial[n] def nck(n, k): if k>n or k<0: return 0 else: return factorial[n] * inv_factorial[n-k] * inv_factorial[k]%MOD def main(): n,m = map(int,input().split()) ans = 0 for i in range(m): if i%2 == 0: ans += nck(m,i) * pow(m - i,n,MOD) % MOD ans %= MOD else: ans -= nck(m,i) * pow(m - i,n,MOD) % MOD ans += MOD ans %= MOD print(ans) if __name__=='__main__': main()