#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long M = 1e9 + 7;
long long F[N], Finv[N], pm[N], pm1[N];
long long inv(long long a, long long p) {
  if (a == 1) return 1;
  return (p - p / a) * inv(p % a, p) % p;
}
long long C(int n, int k) {
  if (k < 0 || k > n) return 0;
  return F[n] * Finv[k] % M * Finv[n - k] % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  F[0] = pm[0] = pm1[0] = 1;
  Finv[0] = inv(F[0], M);
  for (int _n(N), i(1); i < _n; i++) {
    F[i] = F[i - 1] * i % M;
    Finv[i] = inv(F[i], M);
    pm[i] = pm[i - 1] * m % M;
    pm1[i] = pm1[i - 1] * (m - 1) % M;
  }
  long long ans = pm[n];
  for (int _n(n + 1), i(1); i < _n; i++) {
    long long x = 1;
    x = x * pm[i] % M;
    x = x * pm1[n - i] % M;
    x = x * C(n, i - 1) % M;
    ans += x;
    if (ans >= M) ans -= M;
  }
  cout << ans << endl;
  return 0;
}

### 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>
using namespace std;
const int N = 1e6 + 10;
const long long M = 1e9 + 7;
long long F[N], Finv[N], pm[N], pm1[N];
long long inv(long long a, long long p) {
  if (a == 1) return 1;
  return (p - p / a) * inv(p % a, p) % p;
}
long long C(int n, int k) {
  if (k < 0 || k > n) return 0;
  return F[n] * Finv[k] % M * Finv[n - k] % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  F[0] = pm[0] = pm1[0] = 1;
  Finv[0] = inv(F[0], M);
  for (int _n(N), i(1); i < _n; i++) {
    F[i] = F[i - 1] * i % M;
    Finv[i] = inv(F[i], M);
    pm[i] = pm[i - 1] * m % M;
    pm1[i] = pm1[i - 1] * (m - 1) % M;
  }
  long long ans = pm[n];
  for (int _n(n + 1), i(1); i < _n; i++) {
    long long x = 1;
    x = x * pm[i] % M;
    x = x * pm1[n - i] % M;
    x = x * C(n, i - 1) % M;
    ans += x;
    if (ans >= M) ans -= M;
  }
  cout << ans << endl;
  return 0;
}

```