#include <bits/stdc++.h>
using namespace std;
const long long INFLL = 1e18;
const int MAXN = 2e6 + 100;
const long long INF = 1e9;
const long long mod1 = 1e9 + 7;
const long long mod2 = 2e9 + 11;
long long fact[MAXN], ifact[MAXN];
long long bin_pow(long long base, long long deg) {
  if (deg == 0) return 1;
  long long t = bin_pow(base, deg / 2);
  if (deg & 1)
    return (((t * t) % mod1) * base) % mod1;
  else
    return (t * t) % mod1;
}
long long mult(long long a, long long b) { return (a * b) % mod1; }
long long add(long long a, long long b) { return (a + b) % mod1; }
long long C(long long n, long long k) {
  if (k > n) return 0;
  long long ans = fact[n];
  ans = mult(ans, ifact[k]);
  return mult(ans, ifact[n - k]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long f = 1;
  for (long long i = 0; i < MAXN; i++)
    fact[i] = f, f *= (i + 1), f %= mod1, ifact[i] = bin_pow(fact[i], mod1 - 2);
  long long ans = 0;
  for (int k = 1; k <= n - 1; k++) {
    long long sum = fact[n - 2];
    sum = mult(sum, ifact[n - 2 - (k - 1)]);
    sum = mult(sum, C(m - 1, k - 1));
    sum = mult(sum, bin_pow(m, n - k - 1));
    if (n - k - 2 >= 0)
      sum = mult(sum, mult(k + 1, bin_pow(n, n - k - 2)));
    else
      sum = mult(sum, mult(k + 1, bin_pow(bin_pow(n, -(n - k - 2)), mod1 - 2)));
    ans = add(ans, sum);
  }
  cout << ans;
}
