#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long n, m, pw[1000005];
int main() {
  cin >> n >> m;
  long long ans = 0;
  for (int i = pw[0] = 1; i <= n; i++) {
    pw[i] = pw[i - 1] * m % MOD;
  }
  for (int i = n, p = 1; i >= 0; i--) {
    ans = (ans + pw[i] * p) % MOD;
    if (i < n)
      p = p * (2 * m - 1) % MOD;
    else
      p = m;
  }
  cout << ans << endl;
  return 0;
}
