#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, mod = 1e9 + 7;
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= mod) ret -= mod;
  return ret;
}
inline int mult(int a, int b) { return (int)((long long)a * b % mod); }
inline int digni(int x, int y) {
  int ret = 1;
  while (y) {
    if (y % 2 == 1) ret = mult(ret, x);
    x = mult(x, x);
    y /= 2;
  }
  return ret;
}
int n, m, a, b;
int fakt[N], potm[N], potn[N];
int inv[N];
inline int povrh(int nn, int k) {
  if (nn == 0 && k == 0) return 1;
  if (k > nn) return 0;
  return mult(fakt[nn], mult(inv[k], inv[nn - k]));
}
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  fakt[0] = 1;
  potm[0] = 1;
  inv[0] = 1;
  potn[0] = 1;
  for (int i = 1; i <= max(n, m) + 1; i++) {
    fakt[i] = mult(fakt[i - 1], i);
    inv[i] = digni(fakt[i], mod - 2);
    potm[i] = mult(m, potm[i - 1]);
    potn[i] = mult(n, potn[i - 1]);
  }
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int tmp = povrh(m - 1, i - 1);
    tmp = mult(tmp, potm[n - i - 1]);
    tmp = mult(tmp, povrh(n - 2, i - 1));
    tmp = mult(tmp, fakt[i - 1]);
    int t2 = 1;
    if (i < n - 1) t2 = mult(t2, mult(i + 1, potn[n - i - 2]));
    tmp = mult(t2, tmp);
    ans = add(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
