#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  long long ans = 1, em = 1;
  while (n--) {
    ans = ((2 * m - 1) * ans % mod + em) % mod;
    em = em * m % mod;
  }
  cout << ans << endl;
  return 0;
}
