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;
int getint() {
  char ch = getchar();
  int f = 1, x = 0;
  while (!isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const long long MOD = 1000000007;
int n, k;
long long val[1000100];
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    (b & 1) ? res = res * a % MOD : 0;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  long long tx, ty;
  exgcd(b, a % b, tx, ty);
  x = ty;
  y = tx - a / b * ty;
}
long long rev(long long x) {
  x = (x + MOD) % MOD;
  long long tmp, res;
  exgcd(x, MOD, res, tmp);
  res %= MOD;
  res += MOD;
  res %= MOD;
  return res;
}
void init() {
  n = getint(), k = getint();
  val[1] = 1;
  for (int i = 2; i <= k + 2; i++) {
    val[i] = (val[i - 1] + qpow(i, k)) % MOD;
  }
}
int main() {
  init();
  if (n <= k + 2) {
    printf("%I64d\n", val[n]);
  } else {
    long long ans = 0;
    long long tmp = 1;
    for (int i = 2; i <= k + 2; i++) {
      tmp = tmp * (n - i) % MOD;
      tmp = tmp * rev(1 - i) % MOD;
    }
    ans += tmp * val[1];
    ans %= MOD;
    for (int i = 1; i < k + 2; i++) {
      tmp = tmp * (n - i) % MOD;
      tmp = tmp * rev(n - i - 1) % MOD;
      tmp = tmp * rev(i) % MOD;
      tmp = tmp * (MOD + i - k - 2) % MOD;
      ans += tmp * val[i + 1];
      ans %= MOD;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}