#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a, b;
int main() {
  scanf("%d %d", &n, &m);
  a = 0, b = 1;
  for (int i = (1); i <= (n); i++) {
    long long c, d;
    d = 2 * m * b - a;
    a = m * b + (m - 1) * a;
    b = d;
    a %= 1000000007;
    b %= 1000000007;
  }
  printf("%lld\n", (b + 1000000007) % 1000000007);
  return 0;
}
