#include <bits/stdc++.h>
using namespace std;
default_random_engine generator;
uniform_int_distribution<int> distribution(1, INT_MAX);
long long my_rand(long long a = 0, long long b = INT_MAX) {
  return a + distribution(generator) % b;
}
inline int mul(int a, int b) {
  return int(a * 1ll * b % (1000 * 1000 * 1000 + 7));
}
inline int norm(int a) {
  if (a >= (1000 * 1000 * 1000 + 7)) a -= (1000 * 1000 * 1000 + 7);
  if (a < 0) a += (1000 * 1000 * 1000 + 7);
  return a;
}
inline int binPow(int a, int k) {
  int ans = 1;
  while (k > 0) {
    if (k & 1) ans = mul(ans, a);
    a = mul(a, a);
    k >>= 1;
  }
  return ans;
}
inline int subtract(int a, int b) { return norm(a - b); }
inline int sum(int a, int b) { return int((a + b) % (1000 * 1000 * 1000 + 7)); }
inline int inv(int a) { return binPow(a, (1000 * 1000 * 1000 + 7) - 2); }
long long ceil_int(long long a, long long b) { return a / b + (a % b != 0); }
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int n, m, a, b;
vector<int> dp;
long long v1(long long q) { return (3 * q * q - q) / 2; }
long long v2(long long q) { return (3 * q * q + q) / 2; }
int fact[2000000];
int stp[2000000];
int stp2[2000000];
int c_nk(int n1, int k1) {
  if (k1 > n1) return 1;
  return mul(fact[n1], inv(mul(fact[n1 - k1], fact[k1])));
}
int caley(int n, int k) {
  if (n - k - 1 < 0) {
    return mul(k, inv(n));
  }
  return mul(k, stp[n - k - 1]);
}
int main() {
  generator.seed(chrono::system_clock::now().time_since_epoch().count());
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> a >> b;
  fact[0] = 1;
  stp[0] = 1;
  stp2[0] = 1;
  for (int i = 1; i <= 1500000; i++) {
    fact[i] = mul(fact[i - 1], i);
    stp[i] = mul(stp[i - 1], n);
    stp2[i] = mul(stp2[i - 1], m);
  }
  int res = 0;
  for (int edges = 1; edges < n; edges++) {
    if (edges > m) break;
    int vert = edges + 1;
    int free_vert = n - (edges + 1);
    int ways = c_nk(m - 1, edges - 1);
    ways = mul(ways, caley(n, vert));
    ways = mul(ways, stp2[free_vert]);
    ways = mul(ways, c_nk(n - 2, free_vert));
    ways = mul(ways, fact[vert - 2]);
    res = sum(res, ways);
    res = norm(res);
  }
  cout << res;
  return 0;
}
