#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
long long b[(int)1e6 + 5], pp[N];
long long inv[N], invf[N], first[N];
long long c(int x, int y) {
  if (x < 0 || y > x || y < 0) return 0;
  return 1LL * first[x] * invf[y] % mod * invf[x - y] % mod;
}
int n, m, x, y;
void init() {
  inv[1] = 1;
  first[0] = invf[0] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (mod - mod / i) * 1LL * inv[mod % i] % mod;
  }
  for (int i = 1; i < N; i++) {
    first[i] = 1ll * first[i - 1] * i % mod;
  }
  for (int i = 1; i < N; i++) {
    invf[i] = invf[i - 1] * 1LL * inv[i] % mod;
  }
  pp[0] = 1;
  for (int i = 1; i < N; i++) {
    pp[i] = 1ll * pp[i - 1] * m % mod;
  }
}
long long poww(long long x, long long k) {
  long long t = 1;
  while (k) {
    if (k % 2) {
      t = (t * x) % mod;
    }
    x = (x * x) % mod;
    k /= 2;
  }
  return t;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> x >> y;
  init();
  long long ans = 0;
  for (int i = 0; i + 2 <= n && i < m; i++) {
    if (i + 2 == n) {
      ans += c(m - 1, i) * c(n - 2, i) % mod * first[i] % mod;
      ans %= mod;
      continue;
    }
    long long tmp = c(m - 1, i) * c(n - 2, i) % mod;
    tmp = tmp * first[i] % mod;
    tmp = tmp * (i + 2) % mod;
    tmp = tmp * poww(n, n - i - 3) % mod;
    tmp = tmp * pp[n - i - 2] % mod;
    ans += tmp;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
