#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c;
  int a = 0, d = 1;
  while (c = getchar(), c < '0' || c > '9')
    if (c == '-') d = -1;
  a = a * 10 + c - '0';
  while (c = getchar(), c <= '9' && c >= '0') a = a * 10 + c - '0';
  return a * d;
}
const long long mod = 1e9 + 7;
const int M = 1000050;
long long fast(long long a, long long b) {
  if (b < 0) return 1;
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long n, m, a, b, jc[M], jc1[M], inv[M], ans = 0;
long long C(int n, int m) {
  if (n < m || n < 0 || m < 0) return 0;
  return jc[n] * fast(jc[m], mod - 2) % mod * fast(jc[n - m], mod - 2) % mod;
}
long long A(int n, int m) {
  if (n < m || n < 0 || m < 0) return 0;
  return jc[n] * fast(jc[n - m], mod - 2) % mod;
}
int main() {
  n = read();
  m = read();
  a = read();
  b = read();
  jc[0] = jc[1] = 1;
  for (int i = 2; i <= 1000000; i++) {
    jc[i] = jc[i - 1] * i % mod;
  }
  ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (i == n - 1)
      ans =
          (ans + A(n - 2, i - 1) * C(m - 1, i - 1) % mod * fast(m, n - 1 - i)) %
          mod;
    else
      ans = (ans + A(n - 2, i - 1) * C(m - 1, i - 1) % mod * (i + 1) % mod *
                       fast(n, n - i - 2) % mod * fast(m, n - 1 - i)) %
            mod;
  }
  printf("%I64d", ans);
}
