#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n;
int m;
int a, b;
long long fast_mod_pow(long long a, long long b) {
  long long res = 1;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const int MAXN = 1000005;
long long fac[MAXN];
long long invfact[MAXN];
int main() {
  cin >> n >> m >> a >> b;
  long long ans = 0;
  fac[0] = 1;
  fac[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  invfact[MAXN - 1] = fast_mod_pow(fac[MAXN - 1], mod - 2);
  for (int i = MAXN - 2; i >= 0; i--) {
    invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
  }
  for (int i = 1; i <= m; i++) {
    if (i > n - 1) break;
    long long temp = 1;
    temp *= fac[m - 1];
    temp %= mod;
    temp *= invfact[m - i];
    temp %= mod;
    temp *= invfact[i - 1];
    temp %= mod;
    temp *= fac[n - 2];
    temp %= mod;
    temp *= invfact[n - i - 1];
    temp %= mod;
    if ((n - i - 1) == 0) {
      ans += temp;
      ans %= mod;
      continue;
    }
    temp *= fast_mod_pow((long long)m, (long long)(n - i - 1));
    temp %= mod;
    temp *= (i + 1);
    temp %= mod;
    temp *= fast_mod_pow((long long)n, (long long)(n - i - 2));
    temp %= mod;
    ans += temp;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
