#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
long long fac[maxn], c[maxn], exfac[maxn], f[maxn];
long long pow_mod(long long a, long long n) {
  long long d, t;
  d = 1;
  t = a;
  while (n > 0) {
    if (n % 2 == 1) d = (d * t) % mod;
    n = n / 2;
    t = (t * t) % mod;
  }
  return d;
}
int main() {
  long long n, m;
  scanf("%I64d%I64d", &n, &m);
  fac[0] = 1;
  exfac[0] = pow_mod(fac[0], mod - 2);
  for (int i = 1; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    exfac[i] = pow_mod(fac[i], mod - 2);
  }
  c[0] = 1;
  for (int i = 1; i <= n; i++)
    c[i] = (((fac[n] * exfac[i]) % mod) * exfac[n - i]) % mod;
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = (c[i] * pow_mod(m - 1, i)) % mod;
  for (int i = 1; i <= n; i++) f[i] = (f[i] + f[i - 1]) % mod;
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = (ans + (pow_mod(m, i) * f[n - i]) % mod) % mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
