#include <bits/stdc++.h>
using namespace std;
int n, m, ans, f[1000006];
int ksm(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % 1000000007)
    if (b & 1) res = 1ll * res * a % 1000000007;
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == 1) return printf("%d\n", n + 1), 0;
  int inv = ksm(m - 1, 1000000007 - 2);
  int fuck = 1, you = 1, shit = 1;
  ans = ksm(m, n);
  for (int i = 1; i <= n; i++) {
    f[i] = 1LL * fuck * you % 1000000007 * m % 1000000007;
    ans = (ans + 1LL * f[i] * ksm(m, n - i) % 1000000007) % 1000000007;
    fuck = 1LL * fuck * (m - 1) % 1000000007;
    shit = 1LL * shit * inv % 1000000007;
    you = (you + 1LL * f[i] * shit % 1000000007) % 1000000007;
  }
  printf("%d\n", ans);
}

### Prompt

Please create a solution in cpp 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;
int n, m, ans, f[1000006];
int ksm(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % 1000000007)
    if (b & 1) res = 1ll * res * a % 1000000007;
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == 1) return printf("%d\n", n + 1), 0;
  int inv = ksm(m - 1, 1000000007 - 2);
  int fuck = 1, you = 1, shit = 1;
  ans = ksm(m, n);
  for (int i = 1; i <= n; i++) {
    f[i] = 1LL * fuck * you % 1000000007 * m % 1000000007;
    ans = (ans + 1LL * f[i] * ksm(m, n - i) % 1000000007) % 1000000007;
    fuck = 1LL * fuck * (m - 1) % 1000000007;
    shit = 1LL * shit * inv % 1000000007;
    you = (you + 1LL * f[i] * shit % 1000000007) % 1000000007;
  }
  printf("%d\n", ans);
}

```