#include <bits/stdc++.h>
using namespace std;
inline long long Qpow(long long a, long long p) {
  if (p == 0) return 1;
  long long t = Qpow(a, p / 2);
  t = t * t % 1000000007;
  if (p % 2) t = t * a % 1000000007;
  return t;
}
inline long long inv(long long x) { return Qpow(x, 1000000007 - 2); }
long long n, m, a, b, fac[1000005], invfac[1000005], ans;
inline long long A(long long n, long long m) {
  return fac[n] * invfac[n - m] % 1000000007;
}
inline long long C(long long n, long long m) {
  return fac[n] * invfac[n - m] % 1000000007 * invfac[m] % 1000000007;
}
signed main() {
  fac[0] = invfac[0] = 1;
  for (long long i = 1; i <= 1000000; i++)
    fac[i] = fac[i - 1] * i % 1000000007,
    invfac[i] = invfac[i - 1] * inv(i) % 1000000007;
  cin >> n >> m >> a >> b;
  for (long long i = 1; i <= n - 1; i++) {
    if (i > m) break;
    long long nowval = C(m - 1, i - 1);
    nowval = nowval * A(n - 2, i - 1) % 1000000007;
    if (n - i >= 2)
      nowval =
          nowval * (Qpow(n, n - i - 2) * (i + 1) % 1000000007) % 1000000007;
    nowval = nowval * Qpow(m, n - 1 - i) % 1000000007;
    ans = (ans + nowval) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}
