#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int MAX = 1000100;
constexpr int MOD = 1000000007;
i64 fac[MAX], inv[MAX];
i64 ModPow(i64 a, i64 b, i64 p = MOD) {
  i64 ret = 1;
  for (a %= p; b; b >>= 1) {
    if (b & 1) ret = ret * a % p;
    a = a * a % p;
  }
  return ret;
}
inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); }
inline i64 C(int n, int m, i64 p = MOD) {
  return fac[n] * inv[m] % p * inv[n - m] % p;
}
void Init() {
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = Inv(fac[i]);
  }
}
int Solve(int n, int m) {
  i64 ret = ModPow(m, n);
  for (int i = 1; i <= n; ++i) {
    i64 cur = ModPow(m, i) * ModPow(m - 1, n - i) % MOD;
    cur = cur * C(n, i - 1) % MOD;
    ret = (ret + cur) % MOD;
  }
  return (int)ret;
}
int main() {
  Init();
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    printf("%d\n", Solve(n, m));
  }
  return 0;
}

### Prompt

Your challenge is to write 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;
using i64 = long long;
constexpr int MAX = 1000100;
constexpr int MOD = 1000000007;
i64 fac[MAX], inv[MAX];
i64 ModPow(i64 a, i64 b, i64 p = MOD) {
  i64 ret = 1;
  for (a %= p; b; b >>= 1) {
    if (b & 1) ret = ret * a % p;
    a = a * a % p;
  }
  return ret;
}
inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); }
inline i64 C(int n, int m, i64 p = MOD) {
  return fac[n] * inv[m] % p * inv[n - m] % p;
}
void Init() {
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = Inv(fac[i]);
  }
}
int Solve(int n, int m) {
  i64 ret = ModPow(m, n);
  for (int i = 1; i <= n; ++i) {
    i64 cur = ModPow(m, i) * ModPow(m - 1, n - i) % MOD;
    cur = cur * C(n, i - 1) % MOD;
    ret = (ret + cur) % MOD;
  }
  return (int)ret;
}
int main() {
  Init();
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    printf("%d\n", Solve(n, m));
  }
  return 0;
}

```