#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 15;
const int maxe = 2e5 + 15;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int n, m, a, b;
long long pow_mod(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long fac[maxn], ifac[maxn];
long long A(long long a, long long b) {
  if (a < 0 || a - b < 0) return 0;
  return fac[a] * ifac[a - b] % mod;
}
long long C(long long a, long long b) {
  if (a < 0 || b < 0 || a - b < 0) return 0;
  return fac[a] * ifac[a - b] % mod * ifac[b] % mod;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;
  ifac[maxn - 1] = pow_mod(fac[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) {
    ifac[i] = ifac[i + 1] * (i + 1) % mod;
  }
  long long ans = 0;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int edge = 1; edge <= n - 1; edge++) {
    int dnum = edge - 1;
    long long cnt = 1;
    cnt = cnt * A(n - 2, dnum) % mod;
    cnt = cnt * C(m - 1, dnum) % mod;
    cnt = cnt * pow_mod(m, n - edge - 1) % mod;
    if (edge < n - 1)
      cnt = cnt * (edge + 1) % mod * pow_mod(n, n - edge - 2) % mod;
    ans = (ans + cnt) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
