#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 1) {
    printf("%d\n", n + 1);
    return 0;
  }
  int ans = 1LL * m * (power(2 * m - 1, n, mod) - power(m, n, mod) + mod) % mod;
  ans = 1LL * ans * power(m - 1, mod - 2, mod) % mod;
  ans = (ans + power(m, n, mod)) % mod;
  printf("%d\n", ans);
  return 0;
}
