#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e5 + 3, mod = 1e9 + 7;
long long n, m, a, b;
long long pw(long long x, long long y) {
  if (!y) return 1;
  long long nsf = pw(x, y / 2) * pw(x, y / 2) % mod;
  if (y & 1) nsf *= x;
  return nsf % mod;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> a >> b;
  long long fac = 1, c = 1, sum = 0, cnt = 1;
  for (long long i = 2; i <= n && i - 1 <= m; i++) {
    c = c * (i == 2 ? 1ll : (m - i + 2)) % mod * pw(max(1ll, i - 2), mod - 2) %
        mod;
    fac = (fac * max(1ll, i - 2)) % mod;
    if (i > 2) cnt = cnt * (n - i + 1) % mod;
    sum = (sum + pw(m, n - i) * c % mod * (i == n ? 1ll : pw(n, n - i - 1)) %
                     mod * (i == n ? 1ll : i) % mod * cnt % mod) %
          mod;
  }
  cout << sum << endl;
  return 0;
}
