#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long M = 1e9 + 7;
long long fact[N];
long long inv[N];
long long expmod(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = (a * r) % M;
    b >>= 1;
    a = (a * a) % M;
  }
  return r;
}
void initfact() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= M;
  }
  inv[N - 1] = expmod(fact[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1)) % M;
  }
}
long long getC(int a, int b) {
  if (b > a) return 0;
  long long r = (fact[a] * inv[b]) % M;
  return (r * inv[a - b]) % M;
}
long long getA(int a, int b) {
  if (b > a) return 0;
  return (fact[a] * inv[a - b]) % M;
}
long long f(int x, int y) {
  if (x == y) return 1;
  return (y * expmod(x, x - y - 1)) % M;
}
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  initfact();
  long long s = 0;
  for (int e = 1; e < n; e++) {
    long long r = (getA(n - 2, e - 1) * getC(m - 1, e - 1)) % M;
    r = (r * expmod(m, n - e - 1)) % M;
    r = (r * f(n, e + 1)) % M;
    s = (s + r) % M;
  }
  cout << s << endl;
  return 0;
}
