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 long long mod = 1e9 + 7, inf = 1e11, linf = 9223372036854775807;
const long long hashmod[4] = {(int)1e9 + 2277, (int)1e9 + 5277, (int)1e9 + 8277,
                              (int)1e9 + 9277};
const long double EPS = 0.000000000001L, pi = acos(-1);
using namespace std;
long long fast(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = 1LL * res * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return res;
}
long long mul(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res + 1LL * a) % mod;
    a = 1LL * (a + a) % mod;
    b = b >> 1;
  }
  return res;
}
long long pre[1000006];
long long cur[1000006];
int main() {
  int t;
  t = 1;
  pre[0] = 1;
  long long n, k;
  cin >> n >> k;
  vector<long long> f(k + 3, 0);
  f[0] = f[1] = 1;
  long long len = k + 3;
  for (int i = 1; i < len; i++) pre[i] = pre[i - 1] * (i) % mod;
  pre[len - 1] = fast(pre[len - 1], mod - 2) % mod;
  for (int i = len - 1; i >= 1; i--) {
    pre[i - 1] = (pre[i] * i) % mod;
  }
  for (int i = 0; i < len; i++) {
    if (i > 1) f[i] = (f[i - 1] + fast(i, k)) % mod;
    if (i % 2) {
      cur[i] = (mod - pre[i]);
    } else
      cur[i] = pre[i];
  }
  while (t--) {
    for (int i = 2; i <= k + 2; i++) {
      f[i] = (f[i - 1] % mod + fast(i, k)) % mod;
    }
    if (k + 2 >= n) {
      cout << f[n] << '\n';
    } else {
      long long ans = 0;
      long long tmp = 1;
      for (int i = 1; i <= k + 2; i++) {
        tmp = tmp * (n - i) % mod;
      }
      for (int i = 1; i <= k + 2; i++) {
        ans = (ans + f[i] * tmp % mod * pre[i - 1] % mod *
                         fast(n - i, mod - 2) % mod * cur[k + 2 - i] % mod) %
              mod;
      }
      cout << ans % mod << '\n';
    }
  }
}