#include <bits/stdc++.h>
using namespace std;
int N, M, A, B;
long long fac[1000005], ifac[1000005];
long long qpow(long long x, int n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % int(1e9 + 7);
    x = x * x % int(1e9 + 7);
    n /= 2;
  }
  return res;
}
void init() {
  int NN = 1e6;
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= NN; i++) {
    fac[i] = fac[i - 1] * i % int(1e9 + 7);
  }
  ifac[NN] = qpow(fac[NN], int(1e9 + 7) - 2);
  for (int i = NN - 1; i >= 1; i--) {
    ifac[i] = (i + 1) * ifac[i + 1] % int(1e9 + 7);
  }
}
long long comb(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return fac[n] * ifac[k] % int(1e9 + 7) * ifac[n - k] % int(1e9 + 7);
}
long long perm(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return fac[n] * ifac[n - k] % int(1e9 + 7);
}
long long T(int n, int k) {
  if (n <= k)
    return comb(k, n);
  else
    return k * qpow(n, n - k - 1) % int(1e9 + 7);
}
int main() {
  cin >> N >> M >> A >> B;
  init();
  long long ans = 0, ans1;
  for (int i = 0; i <= N - 2; i++) {
    ans1 = perm(N - 2, i) * comb(M - 1, i) % int(1e9 + 7) * qpow(M, N - i - 2) %
           int(1e9 + 7) * T(N, i + 2) % int(1e9 + 7);
    ans = (ans + ans1) % int(1e9 + 7);
  }
  cout << ans << endl;
  return 0;
}
