#include <bits/stdc++.h>
using namespace std;
const long long N = (1 << 20) + 322;
const long long INF = 2e18 + 17;
const long long inf = 2e9 + 17;
const long long mod = 1000000007;
const double eps = 1e-9;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    n >>= 1;
  }
  return res;
}
long long fact[N], inv[N], pw[N];
long long cnk(long long n, long long k) {
  return (((fact[n] * inv[n - k]) % mod) * inv[k]) % mod;
}
long long ank(long long n, long long k) { return (fact[n] * inv[n - k]) % mod; }
long long nk(long long n, long long k) { return (fact[n] * inv[k]) % mod; }
long long n, m, a, b;
void calc() {
  fact[0] = 1;
  inv[0] = 1;
  pw[0] = 1;
  for (long long i = 1; i <= N - 100; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = binpow(fact[i], mod - 2, mod);
    pw[i] = (pw[i - 1] * m) % mod;
  }
}
long long f(long long x, long long y) {
  if (x == y) return 1;
  return y * binpow(x, x - y - 1, mod) % mod;
}
signed main() {
  cin >> n >> m >> a >> b;
  calc();
  long long ans = 0;
  for (long long i = 0; i <= min(m - 1, n - 2); ++i) {
    long long cur = i + 2;
    long long edges = i + 1;
    long long choosefrom = (ank(n - 2, i) * cnk(m - 1, i)) % mod;
    long long treebuild = (f(n, edges + 1) * pw[n - 1 - edges]) % mod;
    choosefrom = (choosefrom * treebuild) % mod;
    ans = (ans + choosefrom) % mod;
  }
  cout << ans;
  return 0;
}
