#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int pre[2000007], inv[2000007];
int power(int a, int b) {
  int res = 1, now = a, left = b;
  while (left > 0) {
    if (left % 2 == 1) res = (1LL * res * now) % 1000000007;
    left /= 2;
    now = (1LL * now * now) % 1000000007;
  }
  return res;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  pre[0] = 1;
  for (int i = 1; i <= 2000000; i++)
    pre[i] = (1LL * pre[i - 1] * i) % 1000000007;
  inv[2000000] = power(pre[2000000], 1000000007 - 2);
  for (int i = 2000000; i; i--) inv[i - 1] = (1LL * inv[i] * i) % 1000000007;
  int ans = 0;
  for (int i = 1; i < n && i <= m; i++) {
    int del = power(m, n - i - 1);
    del = (1LL * del * pre[m - 1]) % 1000000007;
    del = (1LL * del * inv[i - 1]) % 1000000007;
    del = (1LL * del * inv[m - i]) % 1000000007;
    del = (1LL * del * pre[n - 2]) % 1000000007;
    del = (1LL * del * inv[n - i - 1]) % 1000000007;
    if (i < n - 1) {
      del = (1LL * del * (i + 1)) % 1000000007;
      del = (1LL * del * power(n, n - i - 2)) % 1000000007;
    }
    ans = (ans + del) % 1000000007;
  }
  printf("%d\n", ans);
  return 0;
}
