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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
const long long MOD = 1e9 + 7;
long long quick_pow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
long long fact[maxn], p[maxn];
int main() {
  int i, j, n, k;
  fact[0] = 1;
  p[0] = 0;
  for (i = 1; i <= 1000004; i++) fact[i] = (fact[i - 1] * i) % MOD;
  while (scanf("%d%d", &n, &k) != EOF) {
    for (i = 1; i <= k + 2; i++) {
      p[i] = (p[i - 1] + quick_pow(i, k)) % MOD;
    }
    if (n <= k + 2) {
      printf("%I64d\n", p[n]);
      continue;
    }
    long long res = 0, now = 1;
    for (i = 1; i <= k + 2; i++) now = (now * (n - i)) % MOD;
    for (i = 1; i <= k + 2; i++) {
      long long inv = quick_pow(n - i, MOD - 2);
      long long temp = now * inv % MOD;
      long long t = fact[i - 1] * fact[k + 2 - i] % MOD;
      long long sign = (k + 2 - i) % 2 == 1 ? -1 : 1;
      inv = quick_pow(t, MOD - 2);
      res += temp * inv * sign % MOD * p[i];
      res %= MOD;
    }
    if (res < 0) res += MOD;
    printf("%I64d\n", res);
  }
  return 0;
}