#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, ans;
int fc[1000005], rfc[1000005], ri[1000005];
void init() {
  fc[0] = fc[1] = rfc[0] = rfc[1] = ri[1] = 1;
  for (int i = 2; i < 1000005; i++) {
    fc[i] = 1ll * fc[i - 1] * i % mod;
    ri[i] = 1ll * (mod - mod / i) * ri[mod % i] % mod;
    rfc[i] = 1ll * rfc[i - 1] * ri[i] % mod;
  }
}
int C(int n, int k) { return 1ll * rfc[k] * rfc[n - k] % mod * fc[n] % mod; }
int powmod(int a, int b) {
  int rtn = 1;
  for (; b; b >>= 1) {
    if (b & 1) rtn = 1ll * rtn * a % mod;
    a = 1ll * a * a % mod;
  }
  return rtn;
}
int main() {
  init();
  scanf("%d %d", &n, &m);
  ans = powmod(m, n);
  for (int i = 1; i <= n; i++) {
    (ans += 1ll * powmod(m - 1, n - i) * powmod(m, i) % mod * C(n, i - 1) %
            mod) %= mod;
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Generate 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;
const int mod = 1e9 + 7;
int n, m, ans;
int fc[1000005], rfc[1000005], ri[1000005];
void init() {
  fc[0] = fc[1] = rfc[0] = rfc[1] = ri[1] = 1;
  for (int i = 2; i < 1000005; i++) {
    fc[i] = 1ll * fc[i - 1] * i % mod;
    ri[i] = 1ll * (mod - mod / i) * ri[mod % i] % mod;
    rfc[i] = 1ll * rfc[i - 1] * ri[i] % mod;
  }
}
int C(int n, int k) { return 1ll * rfc[k] * rfc[n - k] % mod * fc[n] % mod; }
int powmod(int a, int b) {
  int rtn = 1;
  for (; b; b >>= 1) {
    if (b & 1) rtn = 1ll * rtn * a % mod;
    a = 1ll * a * a % mod;
  }
  return rtn;
}
int main() {
  init();
  scanf("%d %d", &n, &m);
  ans = powmod(m, n);
  for (int i = 1; i <= n; i++) {
    (ans += 1ll * powmod(m - 1, n - i) * powmod(m, i) % mod * C(n, i - 1) %
            mod) %= mod;
  }
  printf("%d\n", ans);
  return 0;
}

```