#include using namespace std; long mod = 0; long getDublicatedPatterns(int cubes, int colors); inline long getCombination(int all, int select); int main(){ int n,m; cin >> n; cin >> m; //cout << "n " << n << " m " << m << endl; int numInkBottol = m; int numWanabePainted =n; long patterns = 1; mod = (long)pow(10,9)+7; if (numWanabePainted > numInkBottol) { patterns = getDublicatedPatterns(numWanabePainted,numInkBottol); //cout << patterns << endl; int plusMinus = 1; for(int i = numInkBottol;i > 0; i--){ patterns = patterns - (plusMinus * getCombination(numInkBottol,i -1) * getDublicatedPatterns(numWanabePainted,i-1)); patterns = patterns % mod; plusMinus *= -1; //cout << patterns << endl; } }else{ //インクの種類が十分多い //順番にインクのバケツにいれる。 for (int i = numInkBottol; i > 0; i--){ patterns = patterns * i; patterns = patterns % mod; } } cout << patterns << endl; } inline long getDublicatedPatterns(int cubes, int colors){ long ret = 1; for(int i = cubes;i>0;i--){ ret = ret*colors; ret = ret % mod; //cout << "i " << i << " colors " <