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 mod = (int)1e9 + 7;
const int N = (int)1e6 + 10;
int n, k, fac[N];
int fpw(int x, int k, int p) {
  int ret = 1;
  while (k) {
    if (k & 1) ret = 1ll * ret * x % p;
    x = 1ll * x * x % p;
    k >>= 1;
  }
  return ret;
}
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int main() {
  scanf("%d %d", &n, &k);
  if (n <= k + 2) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      ans = add(ans, fpw(i, k, mod));
    }
    printf("%d\n", ans);
    return 0;
  }
  fac[0] = 1;
  int x = 1;
  for (int i = 1; i <= k + 2; i++)
    fac[i] = 1ll * fac[i - 1] * i % mod, x = 1ll * (n - i) * x % mod;
  x = (x + mod) % mod;
  int ans = 0, p = 0;
  for (int i = 1; i <= k + 2; i++) {
    p = add(p, fpw(i, k, mod));
    int t = 1ll * x * fpw((n - i), mod - 2, mod) % mod;
    t = 1ll * t *
        fpw(1ll * fac[i - 1] % mod * fac[k + 2 - i] % mod, mod - 2, mod) % mod;
    if ((k + 2 - i) & 1) t = mod - t;
    ans = add(ans, 1ll * p * t % mod);
  }
  printf("%d\n", ans);
  return 0;
}