#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 507, mo = 1e9 + 7;
inline int fk(int x) { return x >= mo ? x - mo : x; }
int n, m, Ans;
int C[N][N], mi[N], m_1i[N];
inline int ksm(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mo;
    x = 1ll * x * x % mo;
    y >>= 1;
  }
  return res;
}
int main() {
  n = read(), m = read();
  for (int i = 0; i <= n; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = fk(C[i - 1][j] + C[i - 1][j - 1]);
  }
  mi[0] = m_1i[0] = 1;
  for (int i = 1; i <= n; i++) {
    mi[i] = 1ll * mi[i - 1] * m % mo;
    m_1i[i] = 1ll * m_1i[i - 1] * (m - 1) % mo;
  }
  for (int i = 0; i <= n; i++) {
    int t = 1ll * C[n][i] *
            ksm(fk(1ll * mi[n - i] * m_1i[i] % mo - m_1i[n] + mo), n) % mo;
    i& 1 ? Ans = fk(Ans - t + mo) : Ans = fk(Ans + t);
  }
  printf("%d\n", Ans);
  return 0;
}
