#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int pw = 1, res = 1, md = 1e9 + 7;
  for (int i = 0; i < n; ++i) {
    res = (2LL * m * res - (res - pw) + 5LL * md) % md;
    pw = (pw * 1LL * m) % md;
  }
  cout << res << endl;
  return 0;
}
