#include <bits/stdc++.h>
using namespace std;
const long long N = 1000002, M = 1e9 + 7;
long long pw(long long x, long long y) {
  long long z = 1;
  for (; y; y >>= 1, x = 1ll * x * x % M)
    if (y & 1) z = 1ll * z * x % M;
  return z;
}
void inc(long long &x, long long y) {
  x += y;
  if (x >= M) x -= M;
}
void dec(long long &x, long long y) {
  x -= y;
  if (x < 0) x += M;
}
void Max(long long &x, long long y) {
  if (y > x) x = y;
}
void Min(long long &x, long long y) {
  if (y < x) x = y;
}
long long n, k, p, inv[N], fac[N], ans, i;
long long C(long long n, long long m) {
  if (n < m) return 0;
  return fac[n] * inv[m] % M * inv[n - m] % M;
}
signed main() {
  scanf("%lld%lld", &n, &k);
  fac[0] = 1;
  for (i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % M;
  inv[n] = pw(fac[n], M - 2);
  for (i = n - 1; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % M;
  p = -1;
  for (i = 0; i <= n; i++) {
    p *= -1;
    ans += p * C(n, i) * pw(k - 1, n * i) % M *
           pw((pw(k, n - i) - pw(k - 1, n - i)), n) % M;
  }
  printf("%lld", (ans % M + M) % M);
}
