#include <bits/stdc++.h>
using namespace std;
int N, M, A, B;
long long fact[2000100], ifact[2000100];
long long pw(long long N, long long k) {
  if (!k) return 1;
  if (k % 2) return (pw(N, k - 1) * N) % 1000000007;
  long long ret = pw(N, k / 2);
  return (ret * ret) % 1000000007;
}
inline long long inv(long long N) { return pw(N, 1000000007 - 2); }
inline long long comb(int N, int k) {
  long long ret = fact[N];
  ret = (ret * ifact[k]) % 1000000007;
  ret = (ret * ifact[N - k]) % 1000000007;
  return ret;
}
inline long long aranj(int N, int k) {
  long long ret = fact[N];
  ret = (ret * ifact[N - k]) % 1000000007;
  return ret;
}
inline long long cntsum(long long M, long long k) {
  if (k > M) return 0;
  M -= k;
  return comb(M + k - 1, M);
}
int main() {
  cin >> N >> M >> A >> B;
  fact[0] = 1;
  for (int i = 1; i <= M + N; ++i) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
  }
  ifact[M + N] = inv(fact[N + M]);
  for (int i = M + N; i >= 1; --i) {
    ifact[i - 1] = (ifact[i] * i) % 1000000007;
  }
  long long ret = 0;
  for (int k = 0; k <= N - 2; ++k) {
    long long rez = 1;
    rez = (rez * aranj(N - 2, k)) % 1000000007;
    rez = (rez * cntsum(M, k + 1)) % 1000000007;
    int R = N - k - 2;
    if (R >= 1) {
      rez = (rez * pw(M, R)) % 1000000007;
      rez = (rez * (k + 2)) % 1000000007;
      rez = (rez * pw(N, R - 1)) % 1000000007;
    }
    ret += rez;
  }
  cout << ret % 1000000007 << "\n";
  return 0;
}
