#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long base = 31;
const double eps = 1e-3, pi = acos((double)-1);
void MAIN();
int main() {
  MAIN();
  return 0;
}
const int N = 1 << 20;
int pw(int a, int b) {
  long long ans = 1;
  for (int i = 30; i >= 0; i--) {
    ans = ans * ans % MOD;
    if (b & 1 << i) ans = ans * a % MOD;
  }
  return ans;
}
int f[N], g[N], h[N];
void MAIN() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = 1LL * f[i - 1] * i % MOD;
  for (int i = 1; i <= n; i++) h[i] = pw(i, MOD - 2);
  ans = 0;
  g[0] = 1;
  for (int i = 1; i <= n; i++) g[i] = 1LL * g[i - 1] * h[i] % MOD;
  for (int s = 1; s <= n; s++) {
    ans = (ans + 1LL * pw(m - 1, n - s) * pw(m, s) % MOD * g[n - s] % MOD *
                     g[s - 1] % MOD * h[n - s + 1]) %
          MOD;
  }
  ans = 1LL * ans * f[n] % MOD;
  ans = (ans + pw(m, n)) % MOD;
  printf("%d\n", ans);
}

### Prompt

Please formulate 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 = (int)1e9 + 7;
const long long base = 31;
const double eps = 1e-3, pi = acos((double)-1);
void MAIN();
int main() {
  MAIN();
  return 0;
}
const int N = 1 << 20;
int pw(int a, int b) {
  long long ans = 1;
  for (int i = 30; i >= 0; i--) {
    ans = ans * ans % MOD;
    if (b & 1 << i) ans = ans * a % MOD;
  }
  return ans;
}
int f[N], g[N], h[N];
void MAIN() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = 1LL * f[i - 1] * i % MOD;
  for (int i = 1; i <= n; i++) h[i] = pw(i, MOD - 2);
  ans = 0;
  g[0] = 1;
  for (int i = 1; i <= n; i++) g[i] = 1LL * g[i - 1] * h[i] % MOD;
  for (int s = 1; s <= n; s++) {
    ans = (ans + 1LL * pw(m - 1, n - s) * pw(m, s) % MOD * g[n - s] % MOD *
                     g[s - 1] % MOD * h[n - s + 1]) %
          MOD;
  }
  ans = 1LL * ans * f[n] % MOD;
  ans = (ans + pw(m, n)) % MOD;
  printf("%d\n", ans);
}

```