#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
const double PI = acos(-1.0);
long long power(long long base, long long exp, int mod = 1000000007) {
  base = base % mod;
  long long res = 1;
  while (exp > 0) {
    if ((exp & 1)) res = (res * base) % mod;
    base = (base * base) % mod;
    exp = exp >> 1;
  }
  return res;
}
long long modinv(long long a, int m = 1000000007) { return power(a, m - 2); }
long long n, m, a, b;
long long pre[1000005] = {0LL}, fac[1000005] = {0LL};
void prepro() {
  pre[0] = 1;
  for (int i = 1; i <= m - 1; i++)
    pre[i] = pre[i - 1] * (m - i) % 1000000007 * modinv(i) % 1000000007;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 1000000007;
}
long long caley(long long x, long long y) {
  if (x == y)
    return 1LL;
  else
    return y * power(x, x - y - 1) % 1000000007;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(17);
  cin >> n >> m >> a >> b;
  prepro();
  long long ans = 0;
  for (int x = 2; x <= n; x++) {
    ;
    ans = (ans + fac[n - 2] * modinv(fac[n - x]) % 1000000007 * pre[x - 2] %
                     1000000007 * caley(n, x) % 1000000007 * power(m, n - x) %
                     1000000007) %
          1000000007;
  }
  cout << ans << endl;
  ;
  return 0;
}
