#include <bits/stdc++.h>
using namespace std;
template <class T>
constexpr T lcm(T m, T n) {
  return m / __gcd(m, n) * n;
}
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
template <typename I>
void join(ostream &ost, I s, I t, string d = " ") {
  for (auto i = s; i != t; ++i) {
    if (i != s) ost << d;
    ost << *i;
  }
  ost << endl;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &a : v) is >> a;
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
T &chmin(T &a, const U &b) {
  return a = (a <= b ? a : b);
}
template <typename T, typename U>
T &chmax(T &a, const U &b) {
  return a = (a >= b ? a : b);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}
long long int power(long long int n, long long int p, long long int m) {
  long long int ret = 1;
  while (p > 0) {
    if (p & 1) (ret *= n) %= m;
    (n *= n) %= m;
    p /= 2;
  }
  return ret;
}
template <typename T>
long long int mod_inv(T n, T p) {
  return power(n, p - 2, p);
}
template <long long int mod>
class Combination {
 public:
  vector<long long int> facto = {1};
  vector<long long int> ifacto = {1};
  long long int factorial(long long int i) {
    if (i < 0) return 0;
    if (facto.size() <= i) facto.resize(i + 1, -1);
    if (i == 0) return facto[0] = 1;
    long long int j = i;
    for (; j >= 0; --j)
      if (facto[j] != -1) break;
    for (long long int k = j + 1; k <= i; ++k)
      (facto[k] = facto[k - 1] * k) %= mod;
    return facto[i];
  }
  long long int factorial_inverse(long long int i) {
    if (i < 0) return 0;
    if (ifacto.size() <= i) ifacto.resize(i + 1, -1);
    if (ifacto[i] != -1) return ifacto[i];
    return ifacto[i] = mod_inv(factorial(i), mod);
  }
  long long int P(long long int n, long long int k) {
    return (factorial(n) * factorial_inverse(n - k)) % mod;
  }
  long long int C(long long int n, long long int k) {
    return (P(n, k) * factorial_inverse(k)) % mod;
  }
  long long int H(long long int n, long long int k) { return C(n + k - 1, n); }
};
const long long int mod = 1e9 + 7;
long long int f(long long int n, long long int k) {
  if (n - k - 1 < 0) {
    return (k * mod_inv(power(n, -(n - k - 1), mod), mod)) % mod;
  } else {
    return (k * power(n, n - k - 1, mod)) % mod;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  Combination<mod> com;
  int n, m, a, b;
  while (cin >> n >> m >> a >> b) {
    long long int ans = 0;
    for (int i = (1); i <= (n - 1); ++i) {
      long long int t = com.P(n - 2, i - 1) * com.C(m - 1, i - 1) % mod *
                        power(m, n - i - 1, mod) % mod * f(n, i + 1) % mod;
      (ans += t) %= mod;
    }
    cout << ans << endl;
  }
  return 0;
}
