#include <bits/stdc++.h>
using namespace std;
long long fact[2000111];
long long fastPow(long long x, long long y) {
  long long ret = 1LL;
  while (y) {
    if (y & 1) ret = (ret * x) % (1000 * 1000 * 1000 + 7);
    x = (x * x) % (1000 * 1000 * 1000 + 7);
    y >>= 1;
  }
  return ret;
}
long long C(long long x, long long y) {
  long long ret = fact[x];
  ret = (ret * fastPow(fact[y], (1000 * 1000 * 1000 + 7) - 2)) %
        (1000 * 1000 * 1000 + 7);
  ret = (ret * fastPow(fact[x - y], (1000 * 1000 * 1000 + 7) - 2)) %
        (1000 * 1000 * 1000 + 7);
  return ret;
}
long long cayley(long long n, long long k) {
  if (n - k - 1 < 0) return 1;
  return k * fastPow(n, n - k - 1) % (1000 * 1000 * 1000 + 7);
}
void preprocess() {
  fact[0] = 1LL;
  for (long long i = 1; i < 2000111; i++)
    fact[i] = (fact[i - 1] * i) % (1000 * 1000 * 1000 + 7);
}
int main() {
  preprocess();
  long long n, m, a, b;
  scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
  long long ans = 0;
  long long middle_numbering = 1;
  for (long long edges = 1; edges <= min(n - 1, m); edges++) {
    long long edge_weight = (C(m - 1, edges - 1) * fastPow(m, n - 1 - edges)) %
                            (1000 * 1000 * 1000 + 7);
    long long tree_structure = cayley(n, edges + 1);
    ans =
        (ans + (tree_structure * middle_numbering) % (1000 * 1000 * 1000 + 7) *
                   edge_weight % (1000 * 1000 * 1000 + 7)) %
        (1000 * 1000 * 1000 + 7);
    middle_numbering =
        (middle_numbering * (n - 1 - edges)) % (1000 * 1000 * 1000 + 7);
  }
  printf("%lld\n", ans);
  return 0;
}
