#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long power(long long x, long long a) {
  if (a <= 0) return (1);
  long long z = power(x, a / 2);
  z = (z * z) % mod;
  if (a % 2) z = (z * x) % mod;
  return (z);
}
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  if (k == 1)
    ans = 1;
  else {
    vector<long long> fact(n + 1, 1), pwk(n + 1, 1), pwk1(n + 1, 1);
    for (int i = 1; i <= n; i++) {
      fact[i] = i * fact[i - 1];
      fact[i] %= mod;
      pwk[i] = k * pwk[i - 1];
      pwk[i] %= mod;
      pwk1[i] = (k - 1) * pwk1[i - 1];
      pwk1[i] %= mod;
    }
    for (int i = 0; i <= n; i++) {
      long long nci = ((((fact[n] * power(fact[i], mod - 2)) % mod) *
                        power(fact[n - i], mod - 2)) %
                       mod);
      long long var = (pwk[n - i] * pwk1[i] - pwk1[n]) % mod;
      long long add = (nci * power(var, n)) % mod;
      if (i % 2)
        ans -= add;
      else
        ans += add;
      ans %= mod;
    }
  }
  if (ans < 0) ans += mod;
  cout << ans << endl;
}
