#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
inline long long int pow(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
inline long long int invmod(long long int x, long long int p) {
  return pow(x, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  if (m == 1) return cout << n + 1, 0;
  long long int a = pow(2 * m - 1, n, 1000000007);
  long long int b = pow(m, n, 1000000007);
  long long int c = invmod(m - 1, 1000000007);
  long long int x = ((a - b) * c) % 1000000007;
  x = (x * m) % 1000000007;
  x = (x + b) % 1000000007;
  cout << x;
}
