#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;
int n, m, F[N], P[N], S[N], dp[N];
int FE(int x, int k) {
  if (!k) return 1;
  long long temp = FE(x, k / 2);
  if (k & 1) return temp * temp % mod * x % mod;
  return temp * temp % mod;
}
int C(int x, int y) { return P[x] * (long long)F[y] % mod * F[x - y] % mod; }
int f(int x) {
  if (x == n + 1) return 0;
  int &r = dp[x];
  if (r != -1) return r;
  r = FE(m, n - x + 1);
  return r = (r + f(x + 1) * (long long)(m + m - 1)) % mod;
}
int main() {
  scanf("%d %d", &n, &m);
  P[0] = 1;
  F[0] = 1;
  for (int i = 1; i <= n; i++) {
    P[i] = i * (long long)P[i - 1] % mod;
    F[i] = FE(P[i], mod - 2);
  }
  memset(dp, -1, sizeof dp);
  cout << (f(1) + FE(m, n)) % mod << '\n';
  return 0;
}

### Prompt

In cpp, your task is to solve 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 long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;
int n, m, F[N], P[N], S[N], dp[N];
int FE(int x, int k) {
  if (!k) return 1;
  long long temp = FE(x, k / 2);
  if (k & 1) return temp * temp % mod * x % mod;
  return temp * temp % mod;
}
int C(int x, int y) { return P[x] * (long long)F[y] % mod * F[x - y] % mod; }
int f(int x) {
  if (x == n + 1) return 0;
  int &r = dp[x];
  if (r != -1) return r;
  r = FE(m, n - x + 1);
  return r = (r + f(x + 1) * (long long)(m + m - 1)) % mod;
}
int main() {
  scanf("%d %d", &n, &m);
  P[0] = 1;
  F[0] = 1;
  for (int i = 1; i <= n; i++) {
    P[i] = i * (long long)P[i - 1] % mod;
    F[i] = FE(P[i], mod - 2);
  }
  memset(dp, -1, sizeof dp);
  cout << (f(1) + FE(m, n)) % mod << '\n';
  return 0;
}

```