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 long long mod = 1e9 + 7;
long long f[1000010], fac_inv[1000010], inv[1000010];
void init() {
  inv[1] = 1;
  for (int i = 2; i < 1000010; i++) {
    if (i >= mod) break;
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  fac_inv[0] = 1;
  for (int i = 1; i < 1000010; ++i) fac_inv[i] = fac_inv[i - 1] * inv[i] % mod;
}
long long Pow(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
long long n_k(int n, int k) {
  f[0] = 0;
  for (int i = 1; i <= k + 2; ++i) f[i] = (f[i - 1] + Pow(i, k)) % mod;
  if (n <= k + 2) return f[n];
  long long cur = 1, ans = 0;
  for (int i = 1; i <= k + 2; ++i) cur = cur * (n - i) % mod;
  for (int i = 1; i <= k + 2; ++i) {
    long long inv1 = Pow(n - i, mod - 2);
    long long inv2 = fac_inv[i - 1] * fac_inv[k + 2 - i] % mod;
    int sign = (k + 2 - i) % 2 ? -1 : 1;
    ans = (ans + sign * inv1 * inv2 % mod * f[i] % mod * cur % mod) % mod;
  }
  ans = ans + mod;
  if (ans >= mod) ans -= mod;
  return ans;
}
int main() {
  init();
  int n, k;
  cin >> n >> k;
  cout << n_k(n, k) << endl;
  return 0;
}