#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long fac[1000100], ifac[1000100];
long long pw1[1000100], pw2[1000100];
long long n, m;
long long Pow(long long x, long long y) {
  if (y == 0) return 1;
  long long res = Pow(x, y >> 1);
  res = res * res % mod;
  if (y & 1) res = res * x % mod;
  return res;
}
long long C(long long x, long long y) {
  return fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int main() {
  cin >> n >> m;
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
    ifac[i] = Pow(fac[i], mod - 2);
  }
  pw1[0] = pw2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw1[i] = pw1[i - 1] * m % mod;
    pw2[i] = pw2[i - 1] * (m - 1) % mod;
  }
  long long ans = Pow(m, n);
  for (int i = 1; i <= n; i++) {
    long long cur = pw2[n - i] * pw1[i] % mod * C(n, i - 1) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).

You are given two positive integers n and m. Let S be the set of all sequences of length n consisting of numbers from 1 to m. Compute the sum f(a) over all a in S modulo 109 + 7.

Input

The only line contains two integers n and m (1 ≤ n, m ≤ 106) — the number of elements in arrays and the upper bound for elements.

Output

Print the only integer c — the desired sum modulo 109 + 7.

Examples

Input

1 3


Output

6


Input

2 2


Output

14


Input

3 3


Output

174

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long fac[1000100], ifac[1000100];
long long pw1[1000100], pw2[1000100];
long long n, m;
long long Pow(long long x, long long y) {
  if (y == 0) return 1;
  long long res = Pow(x, y >> 1);
  res = res * res % mod;
  if (y & 1) res = res * x % mod;
  return res;
}
long long C(long long x, long long y) {
  return fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int main() {
  cin >> n >> m;
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
    ifac[i] = Pow(fac[i], mod - 2);
  }
  pw1[0] = pw2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw1[i] = pw1[i - 1] * m % mod;
    pw2[i] = pw2[i - 1] * (m - 1) % mod;
  }
  long long ans = Pow(m, n);
  for (int i = 1; i <= n; i++) {
    long long cur = pw2[n - i] * pw1[i] % mod * C(n, i - 1) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << endl;
  return 0;
}

```