#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
const int M = 1e9 + 7.1;
int f[maxn], s, n, m;
int mult(int a, int b) {
  long long c;
  c = (long long)a * (long long)b % M;
  return c;
}
int add(int a, int b) {
  int c = a + b;
  if (c >= M) {
    c -= M;
  }
  return c;
}
int sub(int a, int b) {
  if (a < b) {
    a += M;
  }
  return a - b;
}
void solve() {
  f[0] = 1;
  f[1] = 2 * m;
  int tmp = 0;
  for (int i = 2; i <= n; i++) {
    tmp = add(f[i - 2], mult(m - 1, tmp));
    f[i] = mult(m, add(f[i - 1], sub(f[i - 1], tmp)));
  }
  printf("%d\n", f[n]);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    solve();
  }
  return 0;
}
