#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long pw(long long A, long long B) {
  long long RES = 1;
  while (B) {
    if (B & 1) RES = (RES * A) % mod;
    A = (A * A) % mod;
    B >>= 1;
  }
  return RES;
}
long long n, m, a[maxn], fac[maxn], inv[maxn], pm[maxn], pm2[maxn];
long long chs(long long A, long long B) {
  if (A < B) return 0;
  if ((A == B) || (B == 0)) return 1;
  return (fac[A] * inv[B] % mod * inv[A - B] % mod);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fac[0] = 1;
  pm[0] = 1;
  pm2[0] = 1;
  cin >> n >> m;
  for (long long i = 1; i < maxn; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    pm[i] = (pm[i - 1] * m) % mod;
    pm2[i] = (pm2[i - 1] * (m - 1ll)) % mod;
  }
  inv[maxn - 1] = pw(fac[maxn - 1], mod - 2);
  for (long long i = maxn - 2; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1ll)) % mod;
  }
  a[0] = pm2[n];
  long long ans = pm[n];
  for (long long i = 1; i <= n; i++) {
    a[i] = (a[i - 1] + chs(n, i) * pm2[n - i] % mod) % mod;
    ans = (ans + (pm[n] - a[i - 1] + mod) % mod * pm[i] % mod) % mod;
  }
  cout << ans << endl;
}

### Prompt

In CPP, your task is to solve 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 long long maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long pw(long long A, long long B) {
  long long RES = 1;
  while (B) {
    if (B & 1) RES = (RES * A) % mod;
    A = (A * A) % mod;
    B >>= 1;
  }
  return RES;
}
long long n, m, a[maxn], fac[maxn], inv[maxn], pm[maxn], pm2[maxn];
long long chs(long long A, long long B) {
  if (A < B) return 0;
  if ((A == B) || (B == 0)) return 1;
  return (fac[A] * inv[B] % mod * inv[A - B] % mod);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fac[0] = 1;
  pm[0] = 1;
  pm2[0] = 1;
  cin >> n >> m;
  for (long long i = 1; i < maxn; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    pm[i] = (pm[i - 1] * m) % mod;
    pm2[i] = (pm2[i - 1] * (m - 1ll)) % mod;
  }
  inv[maxn - 1] = pw(fac[maxn - 1], mod - 2);
  for (long long i = maxn - 2; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1ll)) % mod;
  }
  a[0] = pm2[n];
  long long ans = pm[n];
  for (long long i = 1; i <= n; i++) {
    a[i] = (a[i - 1] + chs(n, i) * pm2[n - i] % mod) % mod;
    ans = (ans + (pm[n] - a[i - 1] + mod) % mod * pm[i] % mod) % mod;
  }
  cout << ans << endl;
}

```