#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
const long long mod = 1e9 + 7;
long long n, m;
long long kissme(long long x, long long y) {
  long long ret = 1;
  while (y > 0) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  if (m == 1)
    cout << n + 1 << endl;
  else
    cout << (kissme(m, n) + m * kissme(m - 1, mod - 2) % mod *
                                (kissme(2 * m - 1, n) - kissme(m, n) + mod)) %
                mod;
  return 0;
}
