#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long n, m, p, ans, fac[3000000], ifac[3000000];
void upd(long long &x, long long y) { x = (x + y % mod + mod) % mod; }
long long inv(long long x) {
  return x == 1 ? 1 : (mod - mod / x) * inv(mod % x) % mod;
}
long long pw(long long x, long long k) {
  if (!k) return 1;
  long long tmp = pw(x * x % mod, k >> 1);
  return k & 1 ? tmp * x % mod : tmp;
}
long long C(long long x, long long y) {
  return x < y ? 0 : fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
long long P(long long x, long long y) {
  return x < y ? 0 : fac[x] * ifac[x - y] % mod;
}
int main() {
  scanf("%lld%lld%*d%*d", &n, &m);
  p = n + m;
  fac[0] = 1;
  for (long long i = 1; i <= p; ++i) fac[i] = fac[i - 1] * i % mod;
  ifac[p] = inv(fac[p]);
  for (long long i = p - 1; ~i; --i) ifac[i] = ifac[i + 1] * (i + 1) % mod;
  for (long long k = 1; k < n - 1; ++k)
    upd(ans, P(n - 2, k - 1) * C(m - 1, k - 1) % mod * pw(m, n - k - 1) % mod *
                 pw(n, n - k - 2) % mod * (k + 1));
  upd(ans, fac[n - 2] * C(m - 1, n - 2));
  printf("%lld\n", ans);
  return 0;
}
