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 = 1e6 + 100;
const int mod = 1e9 + 7;
const int mod1 = 1234567891;
long long inv[maxn];
long long qpow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y % 2) ans = ans * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
inline void Init(int n) {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  for (int i = 2; i <= n; i++) inv[i] = inv[i] * inv[i - 1] % mod;
}
long long fac[maxn];
long long f[maxn];
long long fst[maxn];
long long lst[maxn];
int main() {
  Init(maxn - 1);
  int i, j;
  long long n, k;
  fac[0] = 1;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (i = 1; i <= k + 2; i++) {
    f[i] = (f[i - 1] + qpow(i, k)) % mod;
  }
  long long ans = 0;
  if (n <= k + 2) {
    cout << f[n] << endl;
    return 0;
  }
  fst[0] = 1;
  lst[k + 3] = 1;
  for (i = 1; i <= k + 2; i++) {
    fst[i] = fst[i - 1] * (n - i) % mod;
  }
  for (i = k + 2; i >= 1; i--) {
    lst[i] = lst[i + 1] * (n - i) % mod;
  }
  for (i = 1; i <= k + 2; i++) {
    long long now = ((fst[i - 1] * lst[i + 1] % mod)) * f[i] % mod;
    now = now * ((inv[i - 1] * inv[k + 2 - i]) % mod) % mod;
    if ((k + 2 - i) % 2) now = now * -1;
    ans = (ans + now) % mod;
  }
  ans = (ans + mod) % mod;
  cout << ans << endl;
  return 0;
}