#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long long maxn = 1000005;
long long fac[maxn], invfac[maxn];
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 1) return (a * binpow(a, b - 1)) % mod;
  long long v = binpow(a, b / 2);
  return (v * v) % mod;
}
long long inverse(long long i) { return binpow(i, mod - 2); }
long long C(long long n, long long k) {
  return fac[n] * invfac[k] % mod * invfac[n - k] % mod;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fac[0] = 1;
  invfac[0] = inverse(fac[0]);
  for (long long i = 1; i < maxn; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    invfac[i] = inverse(fac[i]);
  }
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long res = 0;
  for (long long mid = 0; mid <= n - 2; mid++) {
    long long k = 2 + mid;
    long long t = (binpow(n, n - k - 1) * k) % mod;
    if (n == k) t = 1;
    long long ways = (t * C(n - 2, mid)) % mod;
    ways = (ways * fac[mid]) % mod;
    ways = (ways * binpow(m, n - 2 - mid)) % mod;
    long long stars = m - 1 - mid;
    long long bars = mid + 1;
    if (stars < 0) continue;
    ways = (ways * C(stars + bars - 1, stars));
    res = (res + ways) % mod;
  }
  cout << res << '\n';
}
