#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, p = 1e9 + 7;
int n, m, jc[N], ny[N], ans, po[N], M[N], mx;
inline int read() {
  int x, f = 1;
  char ch;
  while (!(isdigit(ch = getchar()))) ch == '-' ? f = -1 : f;
  x = ch ^ 48;
  while ((isdigit(ch = getchar()))) x = (x << 1) + (x << 3) + (ch ^ 48);
  return f * x;
}
inline int ksm(long long a, int y) {
  long long b = 1;
  while (y) {
    if (y & 1) b = b * a % p;
    a = a * a % p;
    y >>= 1;
  }
  return b;
}
inline int mu(int x, int y) { return (x + y >= p) ? x + y - p : x + y; }
inline int C(int n, int m) { return 1ll * jc[n] * ny[m] % p * ny[n - m] % p; }
int main() {
  n = read();
  m = read();
  read();
  read();
  mx = max(n, m);
  jc[0] = 1;
  for (int i = 1; i <= mx; i++) jc[i] = 1ll * i * jc[i - 1] % p;
  ny[mx] = ksm(jc[mx], p - 2);
  for (int i = mx; i; i--) ny[i - 1] = 1ll * i * ny[i] % p;
  po[0] = 1;
  for (int i = 1; i <= mx; i++) po[i] = 1ll * n * po[i - 1] % p;
  M[0] = 1;
  for (int i = 1; i <= mx; i++) M[i] = 1ll * m * M[i - 1] % p;
  for (int i = 0; i <= min(m - 1, n - 2); i++) {
    if (i == n - 2)
      ans = mu(ans, 1ll * C(m - 1, i) * jc[i] % p);
    else
      ans = mu(ans, 1ll * C(n - 2, i) * jc[i] % p * C(m - 1, i) % p * (i + 2) %
                        p * po[n - i - 3] % p * M[n - i - 2] % p);
  }
  printf("%d\n", ans);
  return 0;
}
