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