#include <bits/stdc++.h>
using namespace std;
int n, m, fac[2000000], inv[2000000], ans;
int kp(int a, int b) {
  int c = 1;
  while (b) {
    if (b & 1) c = 1ll * c * a % 1000000007;
    a = 1ll * a * a % 1000000007;
    b >>= 1;
  }
  return c;
}
int c(int x, int y) {
  if (x < y) return 0;
  return 1ll * fac[x] * inv[y] % 1000000007 * inv[x - y] % 1000000007;
}
int main() {
  scanf("%d%d%*d%*d", &n, &m);
  fac[0] = 1;
  for (int i = 1; i <= 1000000; i++) fac[i] = 1ll * fac[i - 1] * i % 1000000007;
  inv[1000000] = kp(fac[1000000], 1000000007 - 2);
  for (int i = 1000000; i; i--) inv[i - 1] = 1ll * inv[i] * i % 1000000007;
  ans = 1ll * fac[n - 2] * c(m - 1, n - 2) % 1000000007;
  for (int i = 2; i < n; i++)
    ans = (ans + 1ll * fac[n - 2] * inv[n - i] % 1000000007 * i % 1000000007 *
                     kp(n, n - i - 1) % 1000000007 * kp(m, n - i) % 1000000007 *
                     c(m - 1, i - 2) % 1000000007) %
          1000000007;
  cout << ans;
  return 0;
}
