#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
inline int max(int a, int b) { return a > b ? a : b; }
int n, m, a, b, fac[N], inv[N], pw_n[N], pw_m[N], ans;
inline int combn(int n, int m) {
  if (m < 0 || m > n) return 0;
  return (long long)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  fac[0] = inv[0] = inv[1] = pw_n[0] = pw_m[0] = 1;
  for (int i = 1; i <= max(n, m); ++i) fac[i] = (long long)fac[i - 1] * i % mod;
  for (int i = 2; i <= max(n, m); ++i)
    inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= max(n, m); ++i)
    inv[i] = (long long)inv[i - 1] * inv[i] % mod;
  for (int i = 1; i <= n; ++i) pw_n[i] = (long long)pw_n[i - 1] * n % mod;
  for (int i = 1; i <= n; ++i) pw_m[i] = (long long)pw_m[i - 1] * m % mod;
  for (int i = 1; i < n - 1; ++i) {
    ans = (ans + (long long)combn(m - 1, i - 1) * combn(n - 2, i - 1) % mod *
                     fac[i - 1] % mod * (i + 1) % mod * pw_n[n - i - 2] % mod *
                     pw_m[n - i - 1] % mod) %
          mod;
  }
  ans = (ans + (long long)combn(m - 1, n - 2) * combn(n - 2, n - 2) % mod *
                   fac[n - 2] % mod) %
        mod;
  printf("%d\n", ans);
  return 0;
}
