#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
const int N = 1e6 + 100;
long long M = 1e9 + 7;
long long binpow(long long deg, long long n) {
  if (deg == 0) return 1;
  if (deg & 1) return binpow(deg - 1, n) * n % M;
  long long b = binpow(deg / 2, n);
  return b * b % M;
}
long long n, m;
long long f(long long n) {
  if (n == 1) return m;
  return ((2 * m - 1) * f(n - 1) + binpow(n, m)) % M;
}
int main() {
  cin >> n >> m;
  cout << (f(n) + binpow(n, m)) % M;
  return 0;
}
