#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
const long long MXSZ = 1000000LL;
long long fpow(long long b, long long e) {
  long long ret = 1;
  while (e > 0) {
    if (e & 1) {
      ret = ret * b;
      ret = ret % mod;
    }
    b = b * b % mod;
    e >>= 1;
  }
  return ret;
}
long long fac[MXSZ + 5], inv[MXSZ + 5];
void prec() {
  fac[0] = inv[0] = 1;
  for (long long i = 1; i <= MXSZ + 2; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
    inv[i] = fpow(fac[i], mod - 2) % mod;
  }
}
inline long long comb(long long n, long long k) {
  long long ret = fac[n];
  ret = ret * inv[k];
  ret %= mod;
  ret = ret * inv[n - k];
  ret %= mod;
  return ret;
}
inline long long perm(long long n, long long k) {
  long long ret = fac[n];
  ret = ret * inv[n - k];
  ret %= mod;
  return ret;
}
int n, m, a, b;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  prec();
  cin >> n >> m >> a >> b;
  long long tot = 0LL;
  for (int btwn = 0; btwn <= n - 2; btwn++) {
    if (m < btwn + 1) break;
    long long k = btwn + 2;
    long long vleft = n - k;
    long long curr = 1;
    if (btwn < n - 2) {
      curr *= k;
      curr %= mod;
      curr *= fpow(n, n - k - 1);
      curr %= mod;
    }
    curr *= comb(m - 1, btwn);
    curr %= mod;
    curr *= perm(n - 2, btwn);
    curr %= mod;
    curr *= fpow(m, vleft);
    curr %= mod;
    tot += curr;
    tot %= mod;
  }
  cout << tot << '\n';
  return 0;
}
