#include using namespace std; #define LL long long #define MOD 1000000007 #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) LL pow(LL n, LL m){ LL a = 1; LL i,prod; prod=n; while(m > 0){ if(m % 2 == 1) a = a*prod % MOD; prod = prod*prod %MOD; m /= 2; } return a; } LL ans(LL n, LL m){ LL val = pow(m,n); LL i; LL com = 1; FOR(i,1,m){ com = (com*(m-i+1)/i) % MOD; val = (m-i)%2==0 ? (val + com*pow(i,n)) % MOD : (MOD + (val - com*pow(i,n)) % MOD) % MOD; } return val; } int main(){ LL n,m; cin >> n >> m; cout << ans(n,m) << endl; return 0; }