#include <bits/stdc++.h>
using namespace std;
long long dp[(int)(1e6 + 10)], last, n, m;
int main() {
  cin >> n >> m;
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (((dp[i - 1] * m) % 1000000007) * 2) % 1000000007;
    dp[i] = (dp[i] - (last * m) % 1000000007 + 1000000007) % 1000000007;
    last = (dp[i - 1] + (last * (m - 1)) % 1000000007) % 1000000007;
  }
  cout << dp[n] << '\n';
}
