#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long int inv[MAXN];
long long int fact[MAXN];
long long int power(long long int a, long long int b) {
  long long int r = 1;
  while (b) {
    if (b & 1) r = r * a % 1000000007;
    a = a * a % 1000000007;
    b /= 2ll;
  }
  return r;
}
long long int comb(int n, int k) {
  if (k > n) return 0;
  return fact[n] * inv[n - k] % 1000000007 * inv[k] % 1000000007;
}
long long int solve(int k, int n, int m) {
  if (n == k) return 1ll;
  return (long long int)k * power(n, n - k - 1) % 1000000007 * power(m, n - k) %
         1000000007;
}
long long int categ(int n, int k) { return comb(n - 1, k - 1); }
long long int go(int k, int n, int m) {
  long long int ans = comb(n - 2, k - 2) * categ(m, k - 1) % 1000000007 *
                      fact[k - 2] % 1000000007;
  ans = ans * solve(k, n, m) % 1000000007;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 0; i < MAXN; i++)
    if (i) fact[i] = fact[i - 1] * (long long int)(i) % 1000000007;
  for (int i = 0; i < MAXN; i++) inv[i] = power(fact[i], 1000000007 - 2);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  long long int ans = 0;
  for (int k = 2; k <= n; k++) {
    ans += go(k, n, m);
    ans %= 1000000007;
  }
  cout << ans << '\n';
  return 0;
}
