#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
inline long long int pow(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
inline long long int invmod(long long int x, long long int p) {
  return pow(x, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  if (m == 1) return cout << n + 1, 0;
  long long int a = pow(2 * m - 1, n, 1000000007);
  long long int b = pow(m, n, 1000000007);
  long long int c = invmod(m - 1, 1000000007);
  long long int x = ((a - b) * c) % 1000000007;
  x = (x * m) % 1000000007;
  x = (x + b) % 1000000007;
  cout << x;
}

### Prompt

Create a solution in Cpp for 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;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
inline long long int pow(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
inline long long int invmod(long long int x, long long int p) {
  return pow(x, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  if (m == 1) return cout << n + 1, 0;
  long long int a = pow(2 * m - 1, n, 1000000007);
  long long int b = pow(m, n, 1000000007);
  long long int c = invmod(m - 1, 1000000007);
  long long int x = ((a - b) * c) % 1000000007;
  x = (x * m) % 1000000007;
  x = (x + b) % 1000000007;
  cout << x;
}

```