#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, maxn = 1e6 + 10;
int n, m, a, b, OYYJ;
long long f[maxn], g[maxn], ans;
long long ksm(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % P)
    if (b & 1) ans = ans * a % P;
  return ans;
}
long long C(int n, int k) {
  if (k < 0 || n < k) return 0;
  return f[n] * g[k] % P * g[n - k] % P;
}
long long A(int n, int k) {
  if (k < 0 || n < k) return 0;
  return f[n] * g[n - k] % P;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  f[0] = 1;
  OYYJ = max(n, m);
  for (int i = (1); i <= (OYYJ); ++i) f[i] = f[i - 1] * i % P;
  g[OYYJ] = ksm(f[OYYJ], P - 2);
  for (int i = (OYYJ - 1); i >= (0); --i) g[i] = g[i + 1] * (i + 1) % P;
  for (int i = (1); i <= (n - 1); ++i) {
    long long t = A(n - 2, i - 1) * C(m - 1, i - 1) % P;
    if (i + 2 <= n)
      t = t * (i + 1) % P * ksm(n, n - i - 2) % P * ksm(m, n - i - 1);
    ans = (ans + t) % P;
  }
  cout << ans;
  return 0;
}
