#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <long long MOD>
struct ModInt {
 public:
  static long long pw(long long a, long long b) {
    long long ans = 1;
    while (b) {
      while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
      ans = (ans * a) % MOD, --b;
    }
    return ans;
  }
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x) : x(x % MOD) {}
  ModInt power(ModInt b) { return ModInt(pw(x, b.x)); }
  ModInt operator+(ModInt b) {
    ModInt ans;
    ans.x = x + b.x;
    if (ans.x >= MOD) ans.x -= MOD;
    return ans;
  }
  ModInt &operator+=(ModInt b) {
    x += b.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }
  ModInt operator-(ModInt b) {
    ModInt ans;
    ans.x = x - b.x;
    if (ans.x < 0) ans.x += MOD;
    return ans;
  }
  ModInt &operator-=(ModInt b) {
    x -= b.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt operator-() {
    ModInt ans;
    if (x == 0) return ans;
    ans.x = MOD - x;
    return ans;
  }
  ModInt operator*(ModInt b) { return ModInt(x * b.x); }
  ModInt &operator*=(ModInt b) {
    x = (x * b.x) % MOD;
    return *this;
  }
  ModInt inv() {
    if (MOD >= 2) return ModInt(pw(x, MOD - 2));
    return ModInt();
  }
  ModInt operator/(ModInt b) { return ModInt(x * b.inv().x); }
  ModInt &operator/=(ModInt b) {
    x = (x * b.inv().x) % MOD;
    return *this;
  }
  bool operator==(ModInt b) { return x == b.x; }
  bool operator!=(ModInt b) { return x != b.x; }
};
using num = ModInt<MOD>;
const int MAX = 1E6 + 1;
int n, m;
num fact[MAX];
num ifact[MAX];
void init() {
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = (1); i < (n + 1); ++i) {
    fact[i] = fact[i - 1] * i;
    ifact[i] = fact[i].inv();
  }
}
num C(long long n, long long k) { return fact[n] * ifact[k] * ifact[n - k]; }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  init();
  num res, n2(n), m2(m);
  res = m2.power(n2);
  for (int i = (1); i < (n + 1); ++i) {
    res += m2.power(i) * (m2 - 1).power(n2.x - i) * C(n2.x, i - 1);
  }
  cout << res.x << endl;
  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;
const long long MOD = 1e9 + 7;
template <long long MOD>
struct ModInt {
 public:
  static long long pw(long long a, long long b) {
    long long ans = 1;
    while (b) {
      while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
      ans = (ans * a) % MOD, --b;
    }
    return ans;
  }
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x) : x(x % MOD) {}
  ModInt power(ModInt b) { return ModInt(pw(x, b.x)); }
  ModInt operator+(ModInt b) {
    ModInt ans;
    ans.x = x + b.x;
    if (ans.x >= MOD) ans.x -= MOD;
    return ans;
  }
  ModInt &operator+=(ModInt b) {
    x += b.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }
  ModInt operator-(ModInt b) {
    ModInt ans;
    ans.x = x - b.x;
    if (ans.x < 0) ans.x += MOD;
    return ans;
  }
  ModInt &operator-=(ModInt b) {
    x -= b.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt operator-() {
    ModInt ans;
    if (x == 0) return ans;
    ans.x = MOD - x;
    return ans;
  }
  ModInt operator*(ModInt b) { return ModInt(x * b.x); }
  ModInt &operator*=(ModInt b) {
    x = (x * b.x) % MOD;
    return *this;
  }
  ModInt inv() {
    if (MOD >= 2) return ModInt(pw(x, MOD - 2));
    return ModInt();
  }
  ModInt operator/(ModInt b) { return ModInt(x * b.inv().x); }
  ModInt &operator/=(ModInt b) {
    x = (x * b.inv().x) % MOD;
    return *this;
  }
  bool operator==(ModInt b) { return x == b.x; }
  bool operator!=(ModInt b) { return x != b.x; }
};
using num = ModInt<MOD>;
const int MAX = 1E6 + 1;
int n, m;
num fact[MAX];
num ifact[MAX];
void init() {
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = (1); i < (n + 1); ++i) {
    fact[i] = fact[i - 1] * i;
    ifact[i] = fact[i].inv();
  }
}
num C(long long n, long long k) { return fact[n] * ifact[k] * ifact[n - k]; }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  init();
  num res, n2(n), m2(m);
  res = m2.power(n2);
  for (int i = (1); i < (n + 1); ++i) {
    res += m2.power(i) * (m2 - 1).power(n2.x - i) * C(n2.x, i - 1);
  }
  cout << res.x << endl;
  return 0;
}

```