#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MAX_N = 1000010;
long long fact[MAX_N], fact_inv[MAX_N], inv[MAX_N];
long long pow_mod(long long a, long long b) {
  long long ret;
  if (b < 0)
    ret = pow_mod(a, mod + b - 1);
  else if (b == 0)
    ret = 1;
  else if (b == 1)
    ret = a;
  else {
    long long c = pow_mod(a, b / 2);
    if (b % 2)
      ret = (c * c) % mod * a % mod;
    else
      ret = c * c % mod;
  }
  return ret;
}
void create_table(int n) {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= n; ++i) fact[i] = fact[i - 1] * i % mod;
  fact_inv[n] = pow_mod(fact[n], mod - 2);
  for (int i = n; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i % mod;
  for (int i = 1; i <= n; ++i) inv[i] = fact_inv[i] * fact[i - 1] % mod;
}
long long combi(long long a, long long b) {
  return fact[a] * fact_inv[b] % mod * fact_inv[a - b] % mod;
}
int main() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  create_table(1000000);
  long long ans = 0;
  for (int i = 1; i <= min(n - 1, m); ++i) {
    long long ret = 0;
    ret = fact[n - 2] * fact_inv[n - i - 1] % mod * (i + 1) % mod *
          pow_mod(n, n - i - 2) % mod * fact[m - 1] % mod * fact_inv[m - i] %
          mod * fact_inv[i - 1] % mod * pow_mod(m, n - i - 1) % mod;
    ans += ret;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
