#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long maxn = 1e6 + 5, N = 1e5 + 5, SQ = 450, base = 879169,
                mod = 1e9 + 7, INF = 1e12 + 5, lg = 20;
const long double eps = 1e-4;
long long n, m;
long long s[maxn];
long long fac[maxn], inv[maxn];
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    b /= 2;
    a = (a * a) % mod;
  }
  return res;
}
inline long long C(long long a, long long b) {
  return (((fac[a] * inv[b]) % mod) * inv[a - b]) % mod;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  long long ans = 0;
  s[0] = power(m, n);
  fac[0] = inv[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    fac[i] = (fac[i - 1] * i) % mod;
    inv[i] = power(fac[i], mod - 2);
  }
  for (long long i = 1; i <= n; ++i) {
    s[i] =
        (s[i - 1] - (C(n, i - 1) * power(m - 1, n - i + 1)) % mod + mod) % mod;
    ans = (ans + s[i] * power(m, i)) % mod;
  }
  cout << (ans + s[0]) % mod << '\n';
}
