#include using namespace std; const long long MOD = 1000000007; int main(){ int K; long long N; cin >> K >> N; assert(K <= 2); vector dp000(K + 1, 0); vector dp001(K + 1, 0); vector dp011(K + 1, 0); vector dp012(K + 1, 0); vector dp111(K + 1, 0); vector dp112(K + 1, 0); vector dp123(K + 1, 0); dp000[0] = N; dp001[0] = N - 1; dp011[0] = N - 1; dp012[0] = max(N - 2, (long long) 0); dp111[0] = N - 1; dp112[0] = max(N - 2, (long long) 0); dp123[0] = max(N - 3, (long long) 0); for (int i = 0; i < K; i++){ dp000[i + 1] = N * dp001[i] % MOD * dp001[i] % MOD * dp001[i] % MOD; dp001[i + 1] += (N - 1) * dp001[i] % MOD * dp012[i] % MOD * dp012[i] % MOD; dp001[i + 1] += dp001[i] * dp011[i] % MOD * dp011[i] % MOD; dp001[i + 1] %= MOD; dp011[i + 1] += (N - 1) * dp012[i] % MOD * dp012[i] % MOD * dp112[i] % MOD; dp011[i + 1] += dp011[i] * dp011[i] % MOD * dp111[i] % MOD; dp011[i + 1] %= MOD; if (N >= 2){ dp012[i + 1] += (N - 2) * dp012[i] % MOD * dp012[i] % MOD * dp123[i] % MOD; dp012[i + 1] += 2 * dp011[i] % MOD * dp012[i] % MOD * dp112[i] % MOD; dp012[i + 1] %= MOD; } dp111[i + 1] += (N - 1) * dp112[i] % MOD * dp112[i] % MOD * dp112[i] % MOD; dp111[i + 1] += dp111[i] * dp111[i] % MOD * dp111[i] % MOD; dp111[i + 1] %= MOD; if (N >= 2){ dp112[i + 1] += (N - 2) * dp112[i] % MOD * dp123[i] % MOD * dp123[i] % MOD; dp112[i + 1] += dp112[i] * dp112[i] % MOD * dp111[i] % MOD; dp112[i + 1] += dp112[i] * dp112[i] % MOD * dp112[i] % MOD; dp112[i + 1] %= MOD; } if (N >= 3){ dp123[i + 1] += (N - 3) * dp123[i] % MOD * dp123[i] % MOD * dp123[i] % MOD; dp123[i + 1] += 3 * dp112[i] % MOD * dp123[i] % MOD * dp123[i] % MOD; dp123[i + 1] %= MOD; } } cout << dp000[K] << endl; }