#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
const long long INF = 1001001001001001LL;
const long long MOD = 1000000007LL;
long long int mod_pow(long long int n, long long int k) {
  long long int res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
  }
  return res;
}
signed main() {
  long long int N, M;
  cin >> N >> M;
  long long int ans = mod_pow(M, N), dp = 1;
  for (long long int i = 0; i < N; i++) {
    (ans += (dp * mod_pow(M, N - i) % MOD)) %= MOD;
    dp = (1 + (M - 1) * 2) * dp % MOD;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Develop a solution in Cpp 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;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
const long long INF = 1001001001001001LL;
const long long MOD = 1000000007LL;
long long int mod_pow(long long int n, long long int k) {
  long long int res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
  }
  return res;
}
signed main() {
  long long int N, M;
  cin >> N >> M;
  long long int ans = mod_pow(M, N), dp = 1;
  for (long long int i = 0; i < N; i++) {
    (ans += (dp * mod_pow(M, N - i) % MOD)) %= MOD;
    dp = (1 + (M - 1) * 2) * dp % MOD;
  }
  cout << ans << endl;
  return 0;
}

```