#include <bits/stdc++.h>
int i, j, n, m;
int main() {
  scanf("%d %d", &n, &m);
  long long int T = 1, f = 0, lastT;
  for (i = 1; i <= n; i++) {
    lastT = T;
    T = ((lastT + lastT - f) % 1000000007 + 1000000007) * m % 1000000007;
    f = (lastT + f * (m - 1)) % 1000000007;
  }
  printf("%I64d\n", T);
  return 0;
}
