#include <bits/stdc++.h>
using namespace std;
const long long p = (long long)1e9 + 7;
int n, m, a, b;
long long fac[1000010], inv[1000010];
long long qmod(long long base, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * base % p;
    base = base * base % p;
    n >>= 1;
  }
  return res;
}
long long C(int n, int m) {
  if (m > n) return 0;
  return fac[n] * inv[m] % p * inv[n - m] % p;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 1000000; ++i) fac[i] = fac[i - 1] * i % p;
  inv[1000000] = qmod(fac[1000000], p - 2);
  for (int i = 1000000; i >= 1; --i) inv[i - 1] = inv[i] * i % p;
  while (scanf("%d%d%d%d", &n, &m, &a, &b) != EOF) {
    long long base = 1;
    long long res = 0;
    for (int i = n - 2; i >= 0; --i) {
      base = 1ll * qmod(m, n - 2 - i);
      if (n - i - 3 >= 0) base = base * (i + 2) % p * qmod(n, n - i - 3) % p;
      res = (res + C(m - 1, i) * C(n - 2, i) % p * base % p * fac[i] % p) % p;
    }
    printf("%lld\n", res);
  }
  return 0;
}
