#include <bits/stdc++.h>
using namespace std;
const int mxN = 1000001, MOD = 1e9 + 7;
int n, m;
long long f[mxN], iF[mxN], iv[mxN], pm[mxN], pm1[mxN], p[mxN];
void pc() {
  f[0] = iF[0] = f[1] = iF[1] = iv[1] = 1;
  for (int i = 2; i <= n; ++i) {
    iv[i] = MOD - (MOD / i) * iv[MOD % i] % MOD;
    f[i] = f[i - 1] * i % MOD;
    iF[i] = iF[i - 1] * iv[i] % MOD;
  }
  pm[0] = pm1[0] = 1;
}
long long C(int a, int b) { return f[a] * iF[b] % MOD * iF[a - b] % MOD; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  pc();
  for (int i = 1; i <= n; ++i) {
    pm[i] = pm[i - 1] * m % MOD;
    pm1[i] = pm1[i - 1] * (m - 1) % MOD;
  }
  for (int i = 0; i < n; ++i)
    p[i] = (C(n, i) * pm1[n - i] + (i ? p[i - 1] : 0)) % MOD;
  long long ans = pm[n] + 69696969ll * MOD;
  for (int i = 1; i <= n; ++i) {
    ans += pm[i] * pm[n] % MOD;
    ans -= pm[i] * p[i - 1] % MOD;
  }
  cout << ans % MOD;
  return 0;
}

### Prompt

Create a solution in cpp for 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;
const int mxN = 1000001, MOD = 1e9 + 7;
int n, m;
long long f[mxN], iF[mxN], iv[mxN], pm[mxN], pm1[mxN], p[mxN];
void pc() {
  f[0] = iF[0] = f[1] = iF[1] = iv[1] = 1;
  for (int i = 2; i <= n; ++i) {
    iv[i] = MOD - (MOD / i) * iv[MOD % i] % MOD;
    f[i] = f[i - 1] * i % MOD;
    iF[i] = iF[i - 1] * iv[i] % MOD;
  }
  pm[0] = pm1[0] = 1;
}
long long C(int a, int b) { return f[a] * iF[b] % MOD * iF[a - b] % MOD; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  pc();
  for (int i = 1; i <= n; ++i) {
    pm[i] = pm[i - 1] * m % MOD;
    pm1[i] = pm1[i - 1] * (m - 1) % MOD;
  }
  for (int i = 0; i < n; ++i)
    p[i] = (C(n, i) * pm1[n - i] + (i ? p[i - 1] : 0)) % MOD;
  long long ans = pm[n] + 69696969ll * MOD;
  for (int i = 1; i <= n; ++i) {
    ans += pm[i] * pm[n] % MOD;
    ans -= pm[i] * p[i - 1] % MOD;
  }
  cout << ans % MOD;
  return 0;
}

```