#include <bits/stdc++.h>
using namespace std;
const int M = 1000010, mod = 1000000007;
long long fac[2 * M], fin[2 * M], ans = 0;
int n, m, a, b;
long long bigmod(long long a, long long p) {
  if (p < 0) {
    return bigmod(bigmod(a, -p), mod - 2);
  }
  long long res = 1;
  long long x = a;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
    }
    x = (x * x) % mod;
    p = p >> 1;
  }
  return res;
}
long long comb(int n, int k) {
  if (n < 0 || k < 0 || n < k) {
    return 0;
  }
  return fac[n] * fin[k] % mod * fin[n - k] % mod;
}
long long per(int n, int k) {
  if (n < 0 || k < 0 || n < k) {
    return 0;
  }
  return fac[n] * fin[n - k] % mod;
}
long long wsum(int n, int k) { return comb(n + k - 1, k - 1); }
int main() {
  fac[0] = fin[0] = 1;
  for (long long i = 1; i < 2 * M; i++) {
    fac[i] = i * fac[i - 1] % mod;
    fin[i] = bigmod(fac[i], mod - 2);
  }
  cin >> n >> m >> a >> b;
  for (long long i = n; i >= 2; i--) {
    long long par = wsum(m - (i - 1), i - 1) * per(n - 2, i - 2) % mod;
    (par *= i * bigmod(n, n - i - 1) % mod * bigmod(m, n - i) % mod) %= mod;
    (ans += par) %= mod;
  }
  cout << ans;
  return 0;
}
