#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, m, A[1000009], B[1000009], C[1000009];
inline int Pow(int x, int t) {
  int k = 1;
  while (t)
    k = t & 1 ? 1LL * k * x % 1000000007 : k, t >>= 1,
    x = 1LL * x * x % 1000000007;
  return k;
}
int main() {
  n = read(), m = read();
  A[1] = C[1] = m, B[1] = m - 1;
  for (int i = 2; i <= n; i++)
    A[i] = 1LL * (A[i - 1] + B[i - 1]) * m % 1000000007,
    B[i] = 1LL * (A[i - 1] + B[i - 1]) * (m - 1) % 1000000007,
    C[i] = (1LL * C[i - 1] * m + A[i]) % 1000000007;
  printf("%d\n", (C[n] + Pow(m, n)) % 1000000007);
  return 0;
}

### 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 int read() {
  int x = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, m, A[1000009], B[1000009], C[1000009];
inline int Pow(int x, int t) {
  int k = 1;
  while (t)
    k = t & 1 ? 1LL * k * x % 1000000007 : k, t >>= 1,
    x = 1LL * x * x % 1000000007;
  return k;
}
int main() {
  n = read(), m = read();
  A[1] = C[1] = m, B[1] = m - 1;
  for (int i = 2; i <= n; i++)
    A[i] = 1LL * (A[i - 1] + B[i - 1]) * m % 1000000007,
    B[i] = 1LL * (A[i - 1] + B[i - 1]) * (m - 1) % 1000000007,
    C[i] = (1LL * C[i - 1] * m + A[i]) % 1000000007;
  printf("%d\n", (C[n] + Pow(m, n)) % 1000000007);
  return 0;
}

```