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