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;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int P = 1e9 + 7, K = 1000050;
inline int qpow(int x, int y) {
  static int r;
  r = 1;
  while (y) {
    if (y & 1) r = (long long)r * x % P;
    x = (long long)x * x % P;
    y >>= 1;
  }
  return r;
}
int n, k, fac[K], nfac[K], inv[K];
int y[K], pre[K], suf[K];
inline int calc(int x) {
  int i;
  for (pre[0] = x, i = 1; i <= k; ++i)
    pre[i] = (long long)pre[i - 1] * (x - i) % P;
  for (suf[k + 1] = 1, i = k; i >= 0; --i)
    suf[i] = (long long)suf[i + 1] * (x - i) % P;
  int ans = 0, ret = 0;
  for (i = 1; i <= k; ++i) {
    ret = (long long)nfac[i] * nfac[k - i] % P * suf[i + 1] % P * pre[i - 1] %
          P * y[i] % P;
    if ((k - i) & 1) ret = (P - ret) % P;
    ans += ret;
    ans %= P;
  }
  return ans;
}
int main() {
  int i;
  read(n), read(k);
  if (n <= 1000000) {
    long long sum = 0;
    for (int i = 1; i <= n; ++i) sum += qpow(i, k);
    sum %= P;
    cout << sum << endl;
    return 0;
  }
  fac[0] = nfac[0] = inv[0] = fac[1] = nfac[1] = inv[1] = 1;
  for (i = 2; i <= 1000040; ++i) {
    fac[i] = (long long)fac[i - 1] * i % P;
    inv[i] = (long long)(P - P / i) * inv[P % i] % P;
    nfac[i] = (long long)nfac[i - 1] * inv[i] % P;
  }
  for (y[0] = 0, y[1] = 1, i = 2; i <= k + 3; ++i)
    y[i] = (y[i - 1] + qpow(i, k)) % P;
  k += 3;
  cout << calc(n) << endl;
  return 0;
}