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