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;
long long ksm(long long a, long long x) {
  long long ans = 1, w = a;
  while (x) {
    if (x & 1) ans = ans * w % 1000000007;
    w = w * w % 1000000007;
    x >>= 1;
  }
  return ans;
}
long long n, k, pre[1000005], fac[1000005], suf[1000005], ans, y[1000005];
signed main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= k + 3; ++i)
    y[i] = (y[i - 1] + ksm(i, k)) % 1000000007;
  if (n <= k + 3) {
    printf("%lld", y[n]);
    return 0;
  }
  pre[0] = fac[0] = 1;
  suf[k + 3] = 1;
  for (long long i = k + 2; i; --i) suf[i] = suf[i + 1] * (n - i) % 1000000007;
  for (long long i = 1; i <= k + 2; ++i) {
    pre[i] = pre[i - 1] * (n - i) % 1000000007;
    fac[i] = fac[i - 1] * ksm(i, 1000000007 - 2) % 1000000007;
  }
  for (long long i = 1; i <= k + 2; ++i) {
    ans = (ans +
           y[i] * (pre[i - 1] * suf[i + 1] % 1000000007) % 1000000007 *
               fac[k + 2 - i] % 1000000007 * fac[i - 1] % 1000000007 *
               (((k + 2 - i) & 1) ? -1 : 1) +
           1000000007) %
          1000000007;
  }
  printf("%lld", ans);
  return 0;
}