#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, K, fac[1005], inv[1005], f[1005];
long long power(long long a, long long b) {
  if (!b) return 1;
  long long ret = power(a, b >> 1);
  if (b & 1) return ret * ret % mod * a % mod;
  return ret * ret % mod;
}
long long findinv(long long a) { return power(a, mod - 2); }
long long C(long long n, long long m) {
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  scanf("%lld%lld", &n, &K);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
  inv[n] = findinv(fac[n]);
  for (int i = n; i >= 1; --i) inv[i - 1] = inv[i] * i % mod;
  for (int i = 1; i <= n; ++i)
    f[i] = power((power(K, i) - power(K - 1, i)) % mod, n);
  long long ans = 0;
  for (int i = 0; i <= n; ++i) {
    long long flag = i % 2 ? -1 : 1;
    ans += flag * C(n, i) % mod * power(K - 1, n * i) % mod * f[n - i] % mod;
    ans %= mod;
  }
  ans = (ans + mod) % mod;
  printf("%lld\n", ans);
}
