#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
constexpr ll MOD = 1e9 + 7;
struct Zp {
  ll first;
  Zp(ll a = 0) {
    if (a < 0)
      a = a % MOD + MOD;
    else if (a >= MOD * 2)
      a %= MOD;
    else if (a >= MOD)
      a -= MOD;
    first = a;
  }
  Zp operator+(Zp r) const { return first + r.first; }
  Zp operator-(Zp r) const { return first - r.first + MOD; }
  Zp operator*(Zp r) const { return first * r.first; }
  Zp operator/(Zp r) const { return first * r.inv().first; }
  Zp operator-() const { return MOD - first; }
  Zp inv() const { return pow(MOD - 2); }
  Zp pow(ll e) const {
    if (e < 0) return inv().pow(-e);
    Zp t = 1, m = *this;
    while (e) {
      if (e & 1) t = t * m;
      e >>= 1;
      m = m * m;
    }
    return t;
  }
  Zp& operator+=(Zp r) { return *this = *this + r; }
  Zp& operator-=(Zp r) { return *this = *this - r; }
  Zp& operator*=(Zp r) { return *this = *this * r; }
  Zp& operator/=(Zp r) { return *this = *this / r; }
  void print() { cerr << first; }
};
vector<Zp> fact;
Zp chooseOrdered(int a, int b) { return fact[a] / fact[a - b]; }
Zp choose(int a, int b) { return fact[a] / (fact[b] * fact[a - b]); }
Zp cayley(int a, int b) { return Zp(a).pow(a - b - 1) * b; }
void run() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  fact.resize(max(n, m) + 1, 1);
  for (int i = (2); i < (int((fact).size())); i++) fact[i] = fact[i - 1] * i;
  Zp ans = 0;
  for (int i = (1); i < (min(n, m + 1)); i++)
    ans += chooseOrdered(n - 2, i - 1) * cayley(n, i + 1) *
           choose(m - 1, i - 1) * Zp(m).pow(n - i - 1);
  cout << ans.first << endl;
}
