#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  return is >> p.first >> p.second;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  return os << p.first << " " << p.second;
}
const int base = 1000000007;
const int N = 1000006;
int binpow(int a, int n) {
  int res = 1;
  if (n < 0) n += base - 1;
  while (n) {
    if (n & 1) res = res * 1ll * a % base;
    a = a * 1ll * a % base;
    n >>= 1;
  }
  return res;
}
int fact[N], invfact[N];
int cnk(int n, int k) {
  if (n < k) return 0;
  return (fact[n] * 1ll * invfact[k] % base) * 1ll * invfact[n - k] % base;
}
int ank(int n, int k) {
  if (n < k) return 0;
  return fact[n] * 1ll * invfact[n - k] % base;
}
int f(int x, int y) { return y * 1ll * binpow(x, x - y - 1) % base; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * 1ll * i % base;
  invfact[N - 1] = binpow(fact[N - 1], base - 2);
  for (int i = N - 2; i >= 0; i--)
    invfact[i] = invfact[i + 1] * 1ll * (i + 1) % base;
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += (((ank(n - 2, i - 1) * 1ll * f(n, i + 1)) % base) *
            cnk(m - 1, i - 1) % base) *
           binpow(m, n - i - 1) % base;
    if (ans >= base) ans -= base;
  }
  cout << ans;
}
