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