#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 2100005, H = 3, p = 1000000007;
int n, m, fac[maxn], inv[maxn];
int G[maxn], F[maxn];
int qpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = (long long)a * a % p)
    if (b & 1) ret = (long long)ret * a % p;
  return ret;
}
int C(int n, int m) { return (long long)fac[n] * inv[m] % p * inv[n - m] % p; }
int main() {
  n = rd(), m = rd();
  F[0] = fac[0] = 1;
  for (int i = int(1); i <= (int)(n); i++)
    F[i] = (long long)F[i - 1] * (m - 1) % p;
  for (int i = n, xs = 1; i >= 0; i--, xs = (long long)xs * m % p)
    F[i] = (long long)F[i] * xs % p;
  for (int i = int(1); i <= (int)(n); i++)
    fac[i] = (long long)fac[i - 1] * i % p;
  inv[n] = qpow(fac[n], p - 2);
  for (int i = int(n - 1); i >= (int)(0); i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % p;
  int ans = qpow(m, n);
  for (int i = int(0); i <= (int)(n - 1); i++)
    ans = ((long long)F[i] * C(n, i + 1) + ans) % p;
  rt(ans), putchar('\n');
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 2100005, H = 3, p = 1000000007;
int n, m, fac[maxn], inv[maxn];
int G[maxn], F[maxn];
int qpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = (long long)a * a % p)
    if (b & 1) ret = (long long)ret * a % p;
  return ret;
}
int C(int n, int m) { return (long long)fac[n] * inv[m] % p * inv[n - m] % p; }
int main() {
  n = rd(), m = rd();
  F[0] = fac[0] = 1;
  for (int i = int(1); i <= (int)(n); i++)
    F[i] = (long long)F[i - 1] * (m - 1) % p;
  for (int i = n, xs = 1; i >= 0; i--, xs = (long long)xs * m % p)
    F[i] = (long long)F[i] * xs % p;
  for (int i = int(1); i <= (int)(n); i++)
    fac[i] = (long long)fac[i - 1] * i % p;
  inv[n] = qpow(fac[n], p - 2);
  for (int i = int(n - 1); i >= (int)(0); i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % p;
  int ans = qpow(m, n);
  for (int i = int(0); i <= (int)(n - 1); i++)
    ans = ((long long)F[i] * C(n, i + 1) + ans) % p;
  rt(ans), putchar('\n');
}

```