#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int pow_mod(int a, int p) {
  int c = 1;
  while (p) {
    if (p & 1) c = (long long)c * a % mod;
    p >>= 1;
    a = (long long)a * a % mod;
  }
  return c;
}
int dp[N], fac[N], inv[N];
inline long long C(int n, int m) {
  return (long long)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (long long)fac[i - 1] * i % mod;
  }
  inv[n] = pow_mod(fac[n], mod - 2);
  for (int i = n - 1; i >= 1; --i) {
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  }
  dp[0] = pow_mod(m, n);
  int p = pow_mod(m - 1, n), mul = pow_mod(m - 1, mod - 2);
  for (int i = 1; i <= n; ++i) {
    int v = C(n, i - 1) * p % mod;
    dp[i] = dp[i - 1] + mod - v;
    if (dp[i] >= mod) dp[i] -= mod;
    p = (long long)p * mul % mod;
  }
  int ans = 0;
  for (int p = 1, i = 0; i <= n; ++i) {
    int v = (long long)dp[i] * p % mod;
    ans += v;
    if (ans >= mod) ans -= mod;
    p = (long long)p * m % mod;
  }
  printf("%d\n", ans);
  return 0;
}
