#include <bits/stdc++.h>
using namespace std;
const int MOD = 1.e9 + 7;
const int MAXN = 1000000;
int fact[MAXN + 5], inv[MAXN + 5];
int lgput(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = 1LL * ans * a % MOD;
    a = 1LL * a * a % MOD;
  }
  return ans;
}
void prec() {
  fact[0] = 1;
  for (int i = 1; i <= MAXN; ++i) fact[i] = 1LL * fact[i - 1] * i % MOD;
  inv[MAXN] = lgput(fact[MAXN], MOD - 2);
  for (int i = MAXN; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % MOD;
}
int comb(int n, int k) {
  return 1LL * fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}
int f(int n, int k) {
  if (k == 0) return 1;
  return 1LL * n * lgput(n + k, k - 1) % MOD;
}
int main() {
  prec();
  int n, m, a, b;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  int ans = 0;
  for (int i = 0; i <= n - 2; ++i) {
    if (m < i + 1) break;
    int aux = 1LL * comb(m - 1, i) * comb(n - 2, i) % MOD * fact[i] % MOD;
    aux = 1LL * aux * lgput(m, n - 2 - i) % MOD * f(i + 2, n - i - 2) % MOD;
    ans += aux;
    if (ans >= MOD) ans -= MOD;
  }
  printf("%d\n", ans);
  return 0;
}
