#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int max(int a, int b) { return a < b ? b : a; }
inline int min(int a, int b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
inline long long min(long long a, long long b) { return a > b ? b : a; }
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long inf = 1e18;
long long power(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  long long b = power(a, n / 2);
  b = b * b % mod;
  if (n % 2) b = b * a % mod;
  return b;
}
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (long long)a * b % mod; }
long long ans[N], sum[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (m == 1) {
    printf("%d\n", n + 1);
    return 0;
  }
  ans[0] = 1;
  for (int i = 1; i < n + 1; ++i) {
    ans[i] = 2 * m * ans[i - 1] % mod;
    sum[i] = sum[i - 1];
    if (i > 1) {
      int j = i - 1;
      sum[i] += m * power(power(m - 1, j), mod - 2) % mod * ans[j - 1] % mod;
      sum[i] %= mod;
    }
    ans[i] -= power(m - 1, i - 1) * sum[i];
    ans[i] %= mod;
  }
  ans[n] = (ans[n] + mod) % mod;
  printf("%lld\n", ans[n]);
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 double eps = 1e-8;
inline int max(int a, int b) { return a < b ? b : a; }
inline int min(int a, int b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
inline long long min(long long a, long long b) { return a > b ? b : a; }
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long inf = 1e18;
long long power(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  long long b = power(a, n / 2);
  b = b * b % mod;
  if (n % 2) b = b * a % mod;
  return b;
}
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (long long)a * b % mod; }
long long ans[N], sum[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (m == 1) {
    printf("%d\n", n + 1);
    return 0;
  }
  ans[0] = 1;
  for (int i = 1; i < n + 1; ++i) {
    ans[i] = 2 * m * ans[i - 1] % mod;
    sum[i] = sum[i - 1];
    if (i > 1) {
      int j = i - 1;
      sum[i] += m * power(power(m - 1, j), mod - 2) % mod * ans[j - 1] % mod;
      sum[i] %= mod;
    }
    ans[i] -= power(m - 1, i - 1) * sum[i];
    ans[i] %= mod;
  }
  ans[n] = (ans[n] + mod) % mod;
  printf("%lld\n", ans[n]);
  return 0;
}

```