#include <bits/stdc++.h>
using namespace std;
long long fac[1000100], ifac[1000100];
long long powmod(long long a, long long b) {
  if (b == 0) return 1;
  long long x = powmod(a, b / 2);
  long long y = (x * x) % 1000000007;
  if (b % 2) return (a * y) % 1000000007;
  return y % 1000000007;
}
int main() {
  fac[0] = 1;
  for (long long i = 1; i < 1000100; i++)
    fac[i] = (fac[i - 1] * i) % 1000000007;
  ifac[1000100 - 1] = powmod(fac[1000100 - 1], 1000000007 - 2);
  for (int i = 1000100 - 2; i >= 1; i--)
    ifac[i] = (ifac[i + 1] * (i + 1)) % 1000000007;
  ifac[0] = 1;
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  if (m == 1) {
    printf("%d\n", n + 1);
    return 0;
  }
  long long ans = powmod(m, n);
  long long one = 1, two = powmod(m - 1, n),
            inv = powmod(m - 1, 1000000007 - 2);
  for (long long s = 1; s < n + 1; s++) {
    one *= m;
    one %= 1000000007;
    two *= inv;
    two %= 1000000007;
    long long tmp = fac[n] * ifac[s - 1];
    tmp %= 1000000007;
    tmp *= ifac[n - s + 1];
    tmp %= 1000000007;
    tmp *= one;
    tmp %= 1000000007;
    tmp *= two;
    tmp %= 1000000007;
    ans = (ans + tmp) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

In CPP, your task is to solve 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;
long long fac[1000100], ifac[1000100];
long long powmod(long long a, long long b) {
  if (b == 0) return 1;
  long long x = powmod(a, b / 2);
  long long y = (x * x) % 1000000007;
  if (b % 2) return (a * y) % 1000000007;
  return y % 1000000007;
}
int main() {
  fac[0] = 1;
  for (long long i = 1; i < 1000100; i++)
    fac[i] = (fac[i - 1] * i) % 1000000007;
  ifac[1000100 - 1] = powmod(fac[1000100 - 1], 1000000007 - 2);
  for (int i = 1000100 - 2; i >= 1; i--)
    ifac[i] = (ifac[i + 1] * (i + 1)) % 1000000007;
  ifac[0] = 1;
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  if (m == 1) {
    printf("%d\n", n + 1);
    return 0;
  }
  long long ans = powmod(m, n);
  long long one = 1, two = powmod(m - 1, n),
            inv = powmod(m - 1, 1000000007 - 2);
  for (long long s = 1; s < n + 1; s++) {
    one *= m;
    one %= 1000000007;
    two *= inv;
    two %= 1000000007;
    long long tmp = fac[n] * ifac[s - 1];
    tmp %= 1000000007;
    tmp *= ifac[n - s + 1];
    tmp %= 1000000007;
    tmp *= one;
    tmp %= 1000000007;
    tmp *= two;
    tmp %= 1000000007;
    ans = (ans + tmp) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}

```