#include <bits/stdc++.h>
using namespace std;
template <class T>
int chkmax(T& a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
int chkmin(T& a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostream& out = cerr) {
  while (begin != end) {
    out << (*begin) << " ";
    begin++;
  }
  out << endl;
}
template <class T>
void output(T x, ostream& out = cerr) {
  output(x.begin(), x.end(), out);
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long MOD = 1e9 + 7;
long long power(long long a, long long deg) {
  long long res = 1;
  while (deg) {
    if ((deg & 1LL) == 0) {
      a = (a * a) % MOD;
      deg >>= 1;
    } else {
      res = (res * a) % MOD;
      deg -= 1;
    }
  }
  return res;
}
long long inverse(long long x) { return power(x, MOD - 2); }
const int mx = 1e6 + 228;
long long fact[mx];
long long C(long long n, long long k) {
  if (k > n) {
    return 0;
  }
  return (fact[n] * inverse(((fact[k]) * fact[n - k]) % MOD)) % MOD;
}
long long n, m;
int a, b;
signed main() {
  fast_io();
  fact[0] = 1;
  for (int i = 1; i < mx; ++i) {
    fact[i] = (fact[i - 1] * (long long)i) % MOD;
  }
  cin >> n >> m >> a >> b;
  long long ans = 0;
  for (long long k = 2; k <= min(n, m + 1); ++k) {
    long long v1 = (C(m - 1, k - 2) * C(n - 2, k - 2)) % MOD;
    v1 = (v1 * fact[k - 2]) % MOD;
    long long d = 1;
    if (k < n) {
      d = (power(n, n - k - 1) * k) % MOD;
    }
    d = (d * power(m, n - k)) % MOD;
    ans = (ans + v1 * d) % MOD;
  }
  cout << ans << endl;
}
