#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
struct modint {
  static const int MOD = 1e9 + 7;
  int val;
  modint(const int v = 0) {
    val = v % MOD;
    if (val < 0) val += MOD;
  }
  modint& operator+=(const modint& other) {
    val += other.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  modint& operator-=(const modint& other) {
    val -= other.val;
    if (val <= 0) val -= MOD;
    return *this;
  }
  modint& operator*=(const modint& other) {
    val = 1LL * val * other.val % MOD;
    return *this;
  }
  modint& operator/=(const modint& other) {
    *this *= other.inv();
    return *this;
  }
  modint operator+(const modint& other) const { return modint(val) += other; }
  modint operator-(const modint& other) const { return modint(val) -= other; }
  modint operator*(const modint& other) const { return modint(val) *= other; }
  modint operator/(const modint& other) const { return modint(val) /= other; }
  static modint pow(const modint& b, ll e) {
    modint res(1);
    modint cur(b);
    for (ll p = 1; p <= e; p <<= 1) {
      if (e & p) {
        res *= cur;
      }
      cur *= cur;
    }
    return res;
  }
  modint pow(ll e) const { return pow(*this, e); }
  modint inv() const { return pow(MOD - 2); }
};
constexpr int MAXN = 1e6 + 6;
modint fact[MAXN];
modint choose(int n, int k) {
  if (n < 0 or k < 0 or k > n) return modint(0);
  return fact[n] / fact[k] / fact[n - k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] * modint(i);
  }
  modint f = modint(m - 1) / modint(m);
  modint b = modint(m).pow(n);
  modint res = b;
  for (int d = 0; d <= n; ++d) {
    modint s = choose(n, n - d - 1);
    modint x = f.pow(d);
    res += s * x * b;
  }
  cout << res.val << '\n';
  return 0;
}

### 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;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
struct modint {
  static const int MOD = 1e9 + 7;
  int val;
  modint(const int v = 0) {
    val = v % MOD;
    if (val < 0) val += MOD;
  }
  modint& operator+=(const modint& other) {
    val += other.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  modint& operator-=(const modint& other) {
    val -= other.val;
    if (val <= 0) val -= MOD;
    return *this;
  }
  modint& operator*=(const modint& other) {
    val = 1LL * val * other.val % MOD;
    return *this;
  }
  modint& operator/=(const modint& other) {
    *this *= other.inv();
    return *this;
  }
  modint operator+(const modint& other) const { return modint(val) += other; }
  modint operator-(const modint& other) const { return modint(val) -= other; }
  modint operator*(const modint& other) const { return modint(val) *= other; }
  modint operator/(const modint& other) const { return modint(val) /= other; }
  static modint pow(const modint& b, ll e) {
    modint res(1);
    modint cur(b);
    for (ll p = 1; p <= e; p <<= 1) {
      if (e & p) {
        res *= cur;
      }
      cur *= cur;
    }
    return res;
  }
  modint pow(ll e) const { return pow(*this, e); }
  modint inv() const { return pow(MOD - 2); }
};
constexpr int MAXN = 1e6 + 6;
modint fact[MAXN];
modint choose(int n, int k) {
  if (n < 0 or k < 0 or k > n) return modint(0);
  return fact[n] / fact[k] / fact[n - k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] * modint(i);
  }
  modint f = modint(m - 1) / modint(m);
  modint b = modint(m).pow(n);
  modint res = b;
  for (int d = 0; d <= n; ++d) {
    modint s = choose(n, n - d - 1);
    modint x = f.pow(d);
    res += s * x * b;
  }
  cout << res.val << '\n';
  return 0;
}

```