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>
const int mo = 1e9 + 7;
int fac[1000005], inv[1000005], f[1000005], invfac[1000005];
int qpow(int a, int b) {
  int res = 1, Pow = a;
  while (b) {
    if (b & 1) res = 1LL * res * Pow % mo;
    Pow = 1LL * Pow * Pow % mo;
    b >>= 1;
  }
  return res;
}
int main() {
  int n, k, K;
  scanf("%d%d", &n, &k);
  int ans = 0;
  K = k;
  k += 2;
  if (n <= k) {
    for (int i = 1; i <= n; i++) ans = (ans + qpow(i, K)) % mo;
    printf("%d\n", ans);
    return 0;
  }
  int prod = 1;
  inv[0] = fac[0] = 1;
  for (int i = 1; i <= k; i++) prod = (1LL * prod * (n - i)) % mo;
  for (int i = 1; i <= k; i++) inv[i] = qpow(n - i, mo - 2);
  for (int i = 1; i <= k; i++) fac[i] = 1LL * fac[i - 1] * i % mo;
  invfac[k] = qpow(fac[k], mo - 2);
  for (int i = k - 1; i >= 0; i--)
    invfac[i] = 1LL * invfac[i + 1] * (i + 1) % mo;
  for (int i = 1; i <= k; i++) {
    f[i] = (f[i - 1] + qpow(i, K)) % mo;
    if ((i + k) & 1)
      ans -= 1LL * f[i] * prod % mo * inv[i] % mo * invfac[i - 1] % mo *
             invfac[k - i] % mo;
    else
      ans += 1LL * f[i] * prod % mo * inv[i] % mo * invfac[i - 1] % mo *
             invfac[k - i] % mo;
    ans %= mo;
    ans += mo;
    ans %= mo;
  }
  printf("%d\n", ans);
}