#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char zf = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + 48);
}
void writeln(const long long y) {
  write(y);
  putchar('\n');
}
int i, j, k, m, n, x, y, z, cnt;
long long ksm(long long x, int y) {
  if (!y) return 1;
  int ew = 1;
  while (y > 1) {
    if (y & 1) y--, ew = x * ew % 1000000007;
    y >>= 1, x = x * x % 1000000007;
  }
  return x * ew % 1000000007;
}
long long a[1000010], jc[1000010], fac[1000010];
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= m + 1; i++)
    a[i] = (a[i - 1] + ksm(i, m)) % 1000000007;
  if (n <= m + 1) {
    cout << a[n];
    return 0;
  }
  long long ans = 0;
  jc[0] = 1;
  jc[1] = n;
  for (register int i = 2; i <= m + 2; i++)
    jc[i] = jc[i - 1] * (n - i + 1) % 1000000007;
  fac[1] = fac[0] = 1;
  for (register int i = 2; i <= m + 2; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  for (register int i = 0; i <= m + 1; i++) {
    long long s1 = jc[m + 2] * ksm(n - i, 1000000007 - 2) % 1000000007;
    long long s2 = fac[i] * fac[m + 1 - i] % 1000000007;
    if (m - i + 1 & 1) s2 = -s2;
    (ans += a[i] * s1 % 1000000007 * ksm(s2, 1000000007 - 2)) %= 1000000007;
  }
  cout << (ans + 1000000007) % 1000000007;
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

There are well-known formulas: <image>, <image>, <image>. Also mathematicians found similar formulas for higher degrees.

Find the value of the sum <image> modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).

Input

The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).

Output

Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.

Examples

Input

4 1


Output

10


Input

4 2


Output

30


Input

4 3


Output

100


Input

4 0


Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char zf = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + 48);
}
void writeln(const long long y) {
  write(y);
  putchar('\n');
}
int i, j, k, m, n, x, y, z, cnt;
long long ksm(long long x, int y) {
  if (!y) return 1;
  int ew = 1;
  while (y > 1) {
    if (y & 1) y--, ew = x * ew % 1000000007;
    y >>= 1, x = x * x % 1000000007;
  }
  return x * ew % 1000000007;
}
long long a[1000010], jc[1000010], fac[1000010];
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= m + 1; i++)
    a[i] = (a[i - 1] + ksm(i, m)) % 1000000007;
  if (n <= m + 1) {
    cout << a[n];
    return 0;
  }
  long long ans = 0;
  jc[0] = 1;
  jc[1] = n;
  for (register int i = 2; i <= m + 2; i++)
    jc[i] = jc[i - 1] * (n - i + 1) % 1000000007;
  fac[1] = fac[0] = 1;
  for (register int i = 2; i <= m + 2; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  for (register int i = 0; i <= m + 1; i++) {
    long long s1 = jc[m + 2] * ksm(n - i, 1000000007 - 2) % 1000000007;
    long long s2 = fac[i] * fac[m + 1 - i] % 1000000007;
    if (m - i + 1 & 1) s2 = -s2;
    (ans += a[i] * s1 % 1000000007 * ksm(s2, 1000000007 - 2)) %= 1000000007;
  }
  cout << (ans + 1000000007) % 1000000007;
  return 0;
}

```