#include <bits/stdc++.h>
using namespace std;
int const mod = (1e9) + 7;
int main() {
  int n, m;
  cin >> n >> m;
  long long ans = 1, deg = m;
  for (int i = 1; i < n; ++i) {
    ans = (ans * (2 * m - 1) + deg) % mod;
    deg = deg * m % mod;
  }
  ans = (m * ans + deg) % mod;
  cout << ans;
  return 0;
}
