#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans(1), t, x;
  scanf("%d%d", &N, &M), t = M, x = (M << 1) - 1;
  for (int i = 1; i <= N; ++i)
    ans = (1ll * ans * M) % 1000000007 + t,
    ans >= 1000000007 ? ans -= 1000000007 : 0, t = 1ll * t * x % 1000000007;
  return printf("%d\n", ans), 0;
}
