#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long a, b, n, m, ans = 0;
long long ar;
long long modularExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % 1000000007, n / 2);
  else
    return (x * modularExponentiation((x * x) % 1000000007, (n - 1) / 2)) %
           1000000007;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
long long modInverse(long long n) {
  return modularExponentiation(n, 1000000007 - 2);
}
long long pmod(long long a, long long b) { return (a * b) % 1000000007; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    cin >> n >> m >> a >> b;
    if (n == 2) {
      cout << "1";
      return 0;
    }
    ar = (2 *
          ((modularExponentiation(m, n - 2) * modularExponentiation(n, n - 3)) %
           1000000007)) %
         1000000007;
    ans = ar;
    for (long long i = 1; i < n - 1; i++) {
      long long x = (((modInverse(i) * modInverse(i + 1)) % 1000000007) *
                     ((modInverse(n) * modInverse(m)) % 1000000007)) %
                    1000000007;
      ar = pmod(pmod(pmod(n - i - 1, m - i), pmod(i + 2, x)), ar);
      ans = (ans + ar) % 1000000007;
    }
    cout << ans;
  }
  return 0;
}
