#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j, k;
void solve(void);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
long long int power(long long int x, long long int n,
                    unsigned long long int m = ULLONG_MAX) {
  long long int res = 1;
  x %= m;
  while (n > 0) {
    if (n & 1 == 1) res = (res * x) % m;
    n /= 2;
    x = (x * x) % m;
  }
  return res;
}
long long int modinv(long long int n) {
  return power(n, 1000000007 - 2, 1000000007);
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int ans = 0;
  long long int c = 1;
  for (i = 1; i <= n; ++i) {
    long long int val = power(m, i, 1000000007);
    val *= power(m - 1, n - i, 1000000007);
    val %= 1000000007;
    if (i > 1) {
      c *= (n - i + 2) % 1000000007;
      c %= 1000000007;
      c *= modinv(i - 1);
      c %= 1000000007;
    }
    val *= c;
    val %= 1000000007;
    ans += val;
    ans %= 1000000007;
  }
  ans += power(m, n, 1000000007);
  ans %= 1000000007;
  cout << ans << '\n';
}

### 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>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j, k;
void solve(void);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
long long int power(long long int x, long long int n,
                    unsigned long long int m = ULLONG_MAX) {
  long long int res = 1;
  x %= m;
  while (n > 0) {
    if (n & 1 == 1) res = (res * x) % m;
    n /= 2;
    x = (x * x) % m;
  }
  return res;
}
long long int modinv(long long int n) {
  return power(n, 1000000007 - 2, 1000000007);
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int ans = 0;
  long long int c = 1;
  for (i = 1; i <= n; ++i) {
    long long int val = power(m, i, 1000000007);
    val *= power(m - 1, n - i, 1000000007);
    val %= 1000000007;
    if (i > 1) {
      c *= (n - i + 2) % 1000000007;
      c %= 1000000007;
      c *= modinv(i - 1);
      c %= 1000000007;
    }
    val *= c;
    val %= 1000000007;
    ans += val;
    ans %= 1000000007;
  }
  ans += power(m, n, 1000000007);
  ans %= 1000000007;
  cout << ans << '\n';
}

```