#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAXN = 1e6 + 7;
int n, m, a, b;
vector<int> fact(MAXN);
vector<int> rfact(MAXN);
inline int pw(int a, int n);
inline int sum(int x, int y);
inline int mult(int x, int y);
inline int A(int n, int k);
inline int F(int x, int y);
inline int C(int n, int k);
inline int pw(int a, int n) {
  int res = 1;
  while (n) {
    if (n % 2 == 0) {
      a = mult(a, a);
      n >>= 1;
    } else {
      res = mult(res, a);
      n--;
    }
  }
  return res;
}
inline int sum(int x, int y) {
  x += y;
  if (x < 0) x += M;
  if (x >= M) x -= M;
  return x;
}
inline int mult(int x, int y) { return ((long long)x * y) % M; }
inline int A(int n, int k) {
  if (k < 0 || n < k) return 0;
  return mult(fact[n], rfact[n - k]);
}
inline int F(int x, int y) { return mult(y, pw(x, x - y - 1 + M - 1)); }
inline int C(int n, int k) {
  if (k < 0 || n < k) return 0;
  return mult(fact[n], mult(rfact[k], rfact[n - k]));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact[0] = 1;
  for (int i = 1; i < MAXN; ++i) fact[i] = mult(fact[i - 1], i);
  rfact[MAXN - 1] = pw(fact[MAXN - 1], M - 2);
  for (int i = MAXN - 2; i >= 0; --i) rfact[i] = mult(rfact[i + 1], i + 1);
  cin >> n >> m >> a >> b;
  int ans = 0;
  for (int i = 1; i < n && i <= m; ++i) {
    int res = mult(A(n - 2, i - 1), F(n, i + 1));
    res = mult(res, C(m - 1, i - 1));
    res = mult(res, pw(m, n - i - 1));
    ans = sum(ans, res);
  }
  cout << ans << endl;
  return 0;
}
