#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 2;
const long long M = 1e9 + 7;
long long f(vector<long long> a, long long m) {
  long long n = a.size();
  vector<long long> dp(m + 1, 0);
  long long all = 1;
  for (long long i = 0; i < n; ++i) {
    long long prev = dp[a[i]];
    dp[a[i]] = all;
    all += (dp[a[i]] - prev + M) % M;
  }
  return all;
}
void dfs(long long n, long long m, vector<long long> &kek,
         set<vector<long long> > &all) {
  if (!n) {
    all.insert(kek);
    return;
  }
  for (long long i = 1; i <= m; ++i) {
    kek[n - 1] = i;
    dfs(n - 1, m, kek, all);
  }
}
long long brute(long long n, long long m) {
  vector<long long> kek(n, 0);
  set<vector<long long> > all;
  dfs(n, m, kek, all);
  long long ret = 0;
  for (auto v : all) {
    ret = (ret + f(v, m)) % M;
  }
  return ret;
}
long long solve(long long n, long long m) {
  long long ret = 1;
  long long emp = 1;
  for (long long i = 0; i < n; ++i) {
    ret = (ret * m + ret * m - ret + emp + M) % M;
    emp = (emp * m) % M;
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  cout << solve(n, m);
}

### 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 long long N = 2e6 + 2;
const long long M = 1e9 + 7;
long long f(vector<long long> a, long long m) {
  long long n = a.size();
  vector<long long> dp(m + 1, 0);
  long long all = 1;
  for (long long i = 0; i < n; ++i) {
    long long prev = dp[a[i]];
    dp[a[i]] = all;
    all += (dp[a[i]] - prev + M) % M;
  }
  return all;
}
void dfs(long long n, long long m, vector<long long> &kek,
         set<vector<long long> > &all) {
  if (!n) {
    all.insert(kek);
    return;
  }
  for (long long i = 1; i <= m; ++i) {
    kek[n - 1] = i;
    dfs(n - 1, m, kek, all);
  }
}
long long brute(long long n, long long m) {
  vector<long long> kek(n, 0);
  set<vector<long long> > all;
  dfs(n, m, kek, all);
  long long ret = 0;
  for (auto v : all) {
    ret = (ret + f(v, m)) % M;
  }
  return ret;
}
long long solve(long long n, long long m) {
  long long ret = 1;
  long long emp = 1;
  for (long long i = 0; i < n; ++i) {
    ret = (ret * m + ret * m - ret + emp + M) % M;
    emp = (emp * m) % M;
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  cout << solve(n, m);
}

```