#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  long long sum = 1;
  long long dp = 0;
  for (int i = 0; i < n; ++i) {
    long long s2 = (long long)m * (2LL * sum - dp + M) % M;
    dp = (sum + dp * (m - 1) % M + M) % M;
    sum = s2;
  }
  cout << sum << endl;
}
