#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int add(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return 1ll * x * y % mod; }
int ksm(int a, int b) {
  if (b < 0) b += mod - 1;
  int ans = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1) ans = mul(ans, a);
  return ans;
}
int fac[maxn], inv[maxn];
int n, m, a, b;
int getc(int a, int b) {
  if (a < b) return 0;
  return mul(fac[a], mul(inv[b], inv[a - b]));
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  fac[0] = 1;
  for (int i = 1; i <= max(n, m); i++) fac[i] = mul(fac[i - 1], i);
  inv[max(n, m)] = ksm(fac[max(n, m)], mod - 2);
  for (int i = max(n, m) - 1; i >= 0; i--) inv[i] = mul(inv[i + 1], i + 1);
  int ans = 0;
  for (int i = 0; i <= n - 2; i++) {
    ans = add(ans, mul(getc(n - 2, i),
                       mul(getc(m - 1, i),
                           mul(ksm(m, n - 2 - i),
                               mul(ksm(n, n - 3 - i), mul(fac[i], i + 2))))));
  }
  printf("%d", ans);
}
