#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  long long r = 2 * m;
  long long s = m;
  for (int i = 2; i <= n; i++) {
    r = (r * (2 * m - 1) + s) % mod;
    (s *= m) %= mod;
  }
  cout << r << endl;
}
