#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6;
long long fact[MAXN];
const long long MOD = 1e9 + 7;
long long pw(long long n, long long k) {
  n %= MOD;
  long long an = 1;
  while (k > 0) {
    if (k & 1) an = (an * n) % MOD;
    n = (n * n) % MOD;
    k >>= 1;
  }
  return an;
}
long long inv(long long k) {
  k %= MOD;
  return pw(k, MOD - 2);
}
long long bin(long long n, long long k) {
  return (fact[n] * inv((fact[k] * fact[n - k]) % MOD)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long n, m;
  int a, b;
  cin >> n >> m >> a >> b;
  if (n == 2) {
    cout << 1;
    return 0;
  }
  fact[0] = 1;
  for (int i = 1; i <= max(m, n); i++) {
    fact[i] = (fact[i - 1] * (long long)i) % MOD;
  }
  long long ans = 0;
  for (int i = 2; i <= min(m + 1, n); i++) {
    ans =
        (ans +
         (((bin(m - 1, i - 2) * bin(n - 2, i - 2)) % MOD * fact[i - 2]) % MOD *
          (i == n ? 1
                  : (((long long)i * (long long)m) % MOD *
                     pw((n * m) % MOD, n - i - 1)) %
                        MOD)) %
             MOD) %
        MOD;
  }
  cout << ans;
  return 0;
}
