#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
  if (x < y) x = y;
}
void chmin(int &x, int y) {
  if (x > y) x = y;
}
int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ret;
}
int n, m, pwm[1000005], pwm1[1000005], fac[1000005], inv[1000005], s[1000005],
    ans;
int C(int x, int y) {
  return (long long)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  scanf("%d%d", &n, &m);
  int N = max(n, m);
  pwm1[0] = 1;
  for (int(i) = (1); (i) <= (N); (i)++)
    pwm1[i] = (long long)pwm1[i - 1] * (m - 1) % mod;
  pwm[0] = 1;
  for (int(i) = (1); (i) <= (N); (i)++)
    pwm[i] = (long long)pwm[i - 1] * m % mod;
  fac[0] = 1;
  for (int(i) = (1); (i) <= (N); (i)++)
    fac[i] = (long long)fac[i - 1] * i % mod;
  inv[N] = qpow(fac[N], mod - 2);
  for (int(i) = (N - 1); (i) >= (0); (i)--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  for (int(i) = (0); (i) <= (n); (i)++) s[i] = (s[i - 1] + pwm[i]) % mod;
  for (int(i) = (0); (i) <= (n); (i)++) {
    ans += (long long)s[i] * C(n, i) % mod * pwm1[n - i] % mod;
    if (ans >= mod) ans -= mod;
  }
  printf("%d\n", ans);
  return 0;
}
