#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
long long fact[maxn];
long long inv[maxn];
long long fiv[maxn];
void init() {
  fact[0] = fact[1] = 1;
  fiv[0] = fiv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= maxn - 1; ++i) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fiv[i] = fiv[i - 1] * inv[i] % mod;
  }
}
long long A(long long n, long long m) { return fact[n] * fiv[n - m] % mod; }
long long C(long long n, long long m) {
  if (n < m || m < 0) return 0;
  return (fact[n] * fiv[m] % mod) * fiv[n - m] % mod;
}
long long qpow(long long a, long long n) {
  if (n == -1) return inv[a];
  long long res = 1;
  long long p = a;
  while (n) {
    if (n & 1) res = res * p % mod;
    p = p * p % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  init();
  long long n, m, a, b;
  scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
  long long ans = 0;
  for (long long i = 1; i <= n - 1; ++i) {
    long long res = (((A(n - 2, i - 1) * C(m - 1, i - 1) % mod) *
                      qpow(m, n - 1 - i) % mod) *
                     qpow(n, n - i - 2) % mod) *
                    (i + 1) % mod;
    ans = (ans + res) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
