#include <bits/stdc++.h>
using namespace std;
long long fn(int i, int mode);
long long dp[1000009][2];
long long const MOD = 1000000007;
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", (fn(0, 1) + fn(0, 0)) % MOD);
  return 0;
}
long long fn(int i, int mode) {
  if (i == n) return mode == 0;
  long long &ret = dp[i][mode];
  if (ret != -1) return ret;
  ret = 0;
  if (mode == 0)
    ret += (m * fn(i + 1, 0)) % MOD;
  else {
    ret += (m * fn(i + 1, 1)) % MOD, ret %= MOD;
    ret += ((m - 1) * fn(i + 1, 1)) % MOD, ret %= MOD;
    ret += fn(i, 0), ret %= MOD;
  }
  return ret;
}

### 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;
long long fn(int i, int mode);
long long dp[1000009][2];
long long const MOD = 1000000007;
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", (fn(0, 1) + fn(0, 0)) % MOD);
  return 0;
}
long long fn(int i, int mode) {
  if (i == n) return mode == 0;
  long long &ret = dp[i][mode];
  if (ret != -1) return ret;
  ret = 0;
  if (mode == 0)
    ret += (m * fn(i + 1, 0)) % MOD;
  else {
    ret += (m * fn(i + 1, 1)) % MOD, ret %= MOD;
    ret += ((m - 1) * fn(i + 1, 1)) % MOD, ret %= MOD;
    ret += fn(i, 0), ret %= MOD;
  }
  return ret;
}

```