#include <bits/stdc++.h>
using namespace std;
struct md {
  int v;
  md(int _v = 0) { v = _v; }
  void operator+=(md a) { v = (0LL + v + a.v + 1000000007) % 1000000007; }
  void operator-=(md a) { v = (0LL + v - a.v + 1000000007) % 1000000007; }
  void operator*=(md a) { v = (1LL * v * a.v) % 1000000007; }
};
md operator+(md a, md b) {
  return md((0LL + a.v + b.v + 1000000007) % 1000000007);
}
md operator-(md a, md b) {
  return md((0LL + a.v - b.v + 1000000007) % 1000000007);
}
md operator*(md a, md b) { return md((1LL * a.v * b.v) % 1000000007); }
md bigmod(md b, long long i) {
  md r(1);
  for (int j = (29); j >= (0); j--) {
    r *= r;
    if ((i >> j) & 1) r *= b;
  }
  return r;
}
md fac[1000005], inv[1000005];
md ncr(int n, int r) {
  if (n < r) return 0;
  return fac[n] * inv[r] * inv[n - r];
}
int main() {
  int n, m, a, b;
  scanf("%d %d %d %d", &n, &m, &a, &b);
  fac[0] = inv[0] = 1;
  for (int i = (1); i <= (max(n, m)); i++) {
    fac[i] = fac[i - 1] * i;
    inv[i] = bigmod(fac[i], 1000000007 - 2);
  }
  md ans = 0;
  for (int i = (0); i <= (n - 3); i++) {
    ans += (i + 2) * bigmod(n, n - i - 3) * ncr(n - 2, i) * fac[i] *
           bigmod(m, (n - 1) - (i + 1)) * ncr(m - 1, i);
  }
  ans += fac[n - 2] * ncr(m - 1, n - 2);
  printf("%d\n", ans.v);
  return 0;
}
