#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
int fac[MAXN], infac[MAXN];
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
int add(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return 1LL * a * b % MOD; }
int C(int a, int b) { return mul(fac[a], mul(infac[b], infac[a - b])); }
int A(int a, int b) { return mul(fac[a], infac[a - b]); }
int F(int a, int b) {
  if (a == b) return 1;
  return mul(b, pow_mod(a, a - b - 1));
}
int main() {
  int n, m, a, b;
  fac[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    fac[i] = mul(i, fac[i - 1]);
  }
  infac[1000000] = pow_mod(fac[1000000], MOD - 2);
  for (int i = 1000000; i >= 1; i--) {
    infac[i - 1] = mul(infac[i], i);
  }
  scanf("%d%d%d%d", &n, &m, &a, &b);
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (i > m) {
      continue;
    }
    ans = add(ans, mul(mul(pow_mod(m, n - 1 - i), F(n, i + 1)),
                       mul(A(n - 2, i - 1), C(m - 1, i - 1))));
  }
  printf("%d", ans);
  return 0;
}
