#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int nmax = 1000005;
const long long inf = 1e9;
long long cnk[nmax];
long long bp[nmax];
long long bp2[nmax];
long long gcdex(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long g = gcdex(b, a % b, x1, y1);
  x = y1;
  y = x1 - a / b * y1;
  return g;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  cnk[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    long long x, y;
    gcdex(i, mod, x, y);
    x = (x % mod + mod) % mod;
    long long cur = ((n - i + 1) * x) % mod;
    cur = (cur * cnk[i - 1]) % mod;
    cnk[i] = cur;
  }
  bp[0] = 1;
  bp2[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    bp[i] = (bp[i - 1] * m) % mod;
    bp2[i] = (bp2[i - 1] * (m - 1ll)) % mod;
  }
  long long dop = bp[n];
  long long ans = dop;
  for (long long s = 1; s <= n; ++s) {
    long long cur = bp[s];
    long long cc = bp2[n - s];
    cur = (cur * cc) % mod;
    cur = (cur * cnk[n - s + 1]) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << '\n';
  return 0;
}

### Prompt

Please create a solution in CPP 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;
const int mod = 1e9 + 7;
const int nmax = 1000005;
const long long inf = 1e9;
long long cnk[nmax];
long long bp[nmax];
long long bp2[nmax];
long long gcdex(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long g = gcdex(b, a % b, x1, y1);
  x = y1;
  y = x1 - a / b * y1;
  return g;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  cnk[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    long long x, y;
    gcdex(i, mod, x, y);
    x = (x % mod + mod) % mod;
    long long cur = ((n - i + 1) * x) % mod;
    cur = (cur * cnk[i - 1]) % mod;
    cnk[i] = cur;
  }
  bp[0] = 1;
  bp2[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    bp[i] = (bp[i - 1] * m) % mod;
    bp2[i] = (bp2[i - 1] * (m - 1ll)) % mod;
  }
  long long dop = bp[n];
  long long ans = dop;
  for (long long s = 1; s <= n; ++s) {
    long long cur = bp[s];
    long long cc = bp2[n - s];
    cur = (cur * cc) % mod;
    cur = (cur * cnk[n - s + 1]) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << '\n';
  return 0;
}

```