#include <bits/stdc++.h>
const long long MOD = 1000000000 + 7;
inline long long fast_pow(long long a, long long b) {
  if (b == 0) return 1;
  long long p = fast_pow(a, b >> 1);
  p = p * p % MOD;
  if (b & 1) p = p * a % MOD;
  return p;
}
inline long long inv(long long f) { return fast_pow(f, MOD - 2) % MOD; }
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  long long n, m;
  std::cin >> n >> m;
  long long mn = 1, sum = 0;
  std::vector<long long> ms(n + 1);
  std::vector<long long> fac(n + 1), rfac(n + 1);
  ms[0] = 1;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    ms[i] = ms[i - 1] * (m - 1) % MOD;
    fac[i] = fac[i - 1] * i % MOD;
  }
  rfac[n] = n;
  for (int i = n - 1; i > 0; i--) {
    rfac[i] = rfac[i + 1] * i % MOD;
  }
  for (int s = 1; s <= n; s++) {
    mn = mn * m % MOD;
    sum += mn * ms[n - s] % MOD * rfac[s] % MOD * inv(fac[n - s + 1]);
    sum %= MOD;
  }
  std::cout << (mn + sum) % MOD;
}

### Prompt

Your task is to create 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>
const long long MOD = 1000000000 + 7;
inline long long fast_pow(long long a, long long b) {
  if (b == 0) return 1;
  long long p = fast_pow(a, b >> 1);
  p = p * p % MOD;
  if (b & 1) p = p * a % MOD;
  return p;
}
inline long long inv(long long f) { return fast_pow(f, MOD - 2) % MOD; }
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  long long n, m;
  std::cin >> n >> m;
  long long mn = 1, sum = 0;
  std::vector<long long> ms(n + 1);
  std::vector<long long> fac(n + 1), rfac(n + 1);
  ms[0] = 1;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    ms[i] = ms[i - 1] * (m - 1) % MOD;
    fac[i] = fac[i - 1] * i % MOD;
  }
  rfac[n] = n;
  for (int i = n - 1; i > 0; i--) {
    rfac[i] = rfac[i + 1] * i % MOD;
  }
  for (int s = 1; s <= n; s++) {
    mn = mn * m % MOD;
    sum += mn * ms[n - s] % MOD * rfac[s] % MOD * inv(fac[n - s + 1]);
    sum %= MOD;
  }
  std::cout << (mn + sum) % MOD;
}

```