#include <bits/stdc++.h>
long long ff[1000000], gg[1000000], pn[1000000], pm[1000000];
long long power(long long a, int k) {
  long long p;
  if (k == 0) return 1;
  p = power(a, k / 2);
  p = p * p % 1000000007;
  if (k % 2) p = p * a % 1000000007;
  return p;
}
void init(int n, int m) {
  long long f, p;
  int i;
  f = 1;
  for (i = 0; i < 1000000; i++) {
    ff[i] = f;
    gg[i] = power(f, 1000000007 - 2);
    f = f * (i + 1) % 1000000007;
  }
  p = 1;
  for (i = 0; i < n; i++) {
    pn[i] = p;
    p = p * n % 1000000007;
  }
  p = 1;
  for (i = 0; i < n; i++) {
    pm[i] = p;
    p = p * m % 1000000007;
  }
}
long long cayley(int n, int k) {
  return k == n ? 1 : k * pn[n - k - 1] % 1000000007;
}
int main() {
  int n, m, a, b, k;
  long long ans;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  init(n, m);
  ans = 0;
  for (k = 0; k <= n - 2 && k < m; k++) {
    long long path = ff[n - 2] * gg[n - 2 - k] % 1000000007;
    long long edges = ff[m - 1] % 1000000007 * gg[k] % 1000000007 *
                      gg[m - 1 - k] % 1000000007 * pm[n - k - 2] % 1000000007;
    ans = (ans + path * cayley(n, k + 2) % 1000000007 * edges) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
