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 N = 2000005, mod = 1e9 + 7;
int n, k, d, tot, f[N], fn[N], gn[N], fac[N], ifac[N], p[N];
bool vis[N];
int exp(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  d = k + 2;
  f[1] = 1;
  for (int i = 2; i <= d; i++) {
    if (!vis[i]) p[++tot] = i, f[i] = exp(i, k);
    for (int j = 1; j <= tot && p[j] * i <= d; j++) {
      vis[p[j] * i] = 1;
      f[p[j] * i] = (long long)f[p[j]] * f[i] % mod;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 1; i <= d; i++) f[i] = (f[i - 1] + f[i]) % mod;
  if (n <= k + 2) {
    printf("%d\n", f[n]);
    return 0;
  }
  fac[0] = 1;
  for (int i = 1; i <= d; i++) fac[i] = (long long)fac[i - 1] * i % mod;
  ifac[d] = exp(fac[d], mod - 2);
  for (int i = d - 1; ~i; i--) ifac[i] = (long long)ifac[i + 1] * (i + 1) % mod;
  fn[0] = gn[d + 1] = 1;
  for (int i = 1; i <= d; i++) fn[i] = (long long)fn[i - 1] * (n - i) % mod;
  for (int i = d; i; i--) gn[i] = (long long)gn[i + 1] * (n - i) % mod;
  int ans = 0;
  for (int i = 1; i <= d; i++) {
    int tmp = (long long)fn[i - 1] % mod * gn[i + 1] % mod * ifac[i - 1] % mod *
              ifac[d - i] % mod * f[i] % mod;
    if (d - i & 1)
      ans = (ans + mod - tmp) % mod;
    else
      ans = (ans + tmp) % mod;
  }
  printf("%d\n", ans);
}