#include <bits/stdc++.h>
using namespace std;
const int tam = 1000010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double DINF = 1e100;
const double EPS = 1e-9;
const double PI = acos(-1);
long long fac[tam], facin[tam];
long long pot(long long b, long long e) {
  long long res = 1;
  while (e > 0) {
    if (e & 1) res = res * b % MOD;
    b = b * b % MOD;
    e /= 2;
  }
  return res;
}
long long bino(int n, int k) {
  return fac[n] * facin[k] % MOD * facin[n - k] % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long res = pot(m, n);
  fac[0] = facin[0] = 1;
  for (int i = 1; i < n + 2; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    facin[i] = pot(fac[i], MOD - 2);
  }
  if (m == 1)
    res += n;
  else
    for (int i = 1; i < n + 1; i++) {
      res += pot(m, i) * pot(m - 1, n - i) % MOD * bino(n, i - 1) % MOD;
      res %= MOD;
    }
  cout << res << '\n';
  return 0;
}

### Prompt

Please formulate 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>
using namespace std;
const int tam = 1000010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double DINF = 1e100;
const double EPS = 1e-9;
const double PI = acos(-1);
long long fac[tam], facin[tam];
long long pot(long long b, long long e) {
  long long res = 1;
  while (e > 0) {
    if (e & 1) res = res * b % MOD;
    b = b * b % MOD;
    e /= 2;
  }
  return res;
}
long long bino(int n, int k) {
  return fac[n] * facin[k] % MOD * facin[n - k] % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long res = pot(m, n);
  fac[0] = facin[0] = 1;
  for (int i = 1; i < n + 2; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    facin[i] = pot(fac[i], MOD - 2);
  }
  if (m == 1)
    res += n;
  else
    for (int i = 1; i < n + 1; i++) {
      res += pot(m, i) * pot(m - 1, n - i) % MOD * bino(n, i - 1) % MOD;
      res %= MOD;
    }
  cout << res << '\n';
  return 0;
}

```