#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6, MOD = 1e9 + 7;
int n, m, a, b;
long long fac[N], ans, ifac[N];
long long qpow(long long u, int v) {
  if (v < 0) {
    return qpow(u, MOD - 1 + v);
  }
  long long rep = 1;
  while (v > 0) {
    if (v & 1) {
      rep = (rep * u) % MOD;
    }
    u = (u * u) % MOD;
    v >>= 1;
  }
  return rep;
}
long long c(int u, int v) {
  if (v < 0 || v > u) {
    return 0;
  }
  return fac[u] * ifac[v] % MOD * ifac[u - v] % MOD;
}
long long p(int u, int v) {
  if (v < 0 || v > u) {
    return 0;
  }
  return fac[u] * ifac[u - v] % MOD;
}
void pre() {
  fac[0] = 1;
  for (int i = 1; i <= 1e6; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
  }
  ifac[(int)1e6] = qpow(fac[(int)1e6], MOD - 2);
  for (int i = 1e6 - 1; ~i; i--) {
    ifac[i] = (ifac[i + 1] * (i + 1)) % MOD;
  }
}
int main() {
  pre();
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 0; i <= n - 2; i++) {
    ans = (ans + (p(n - 2, i) * c(m - 1, i) % MOD * qpow(n, n - i - 3) % MOD *
                  qpow(m, n - i - 2) % MOD * (i + 2) % MOD)) %
          MOD;
  }
  printf("%lld\n", ans);
  return 0;
}
