#include const long long mod = 1000000007; long long N,f[100100],fact[100100]; int K; long long fpow(long long a, long long p) { long long r = 1; while (p){ if (p & 1) r = r * a % mod; a = a * a % mod; p /= 2; } return r; } long long inv(long long a) { return fpow(a, mod-2); } long long proc() { scanf ("%lld %d",&N,&K); N %= mod; for (int i=1;i<=K+1;i++) f[i] = (f[i-1] + fpow(i,K)) % mod; if (N <= K+1) return f[N]; long long ans = 0; for (int i=1;i<=K+1;i++){ long long r = f[i] * inv(fact[i] * fact[K+1-i] % mod * (N - i) % mod) % mod; if (i % 2 == K % 2) r = mod - r; ans = (ans + r) % mod; } for (int i=0;i<=K+1;i++) ans = ans * (N - i) % mod; return ans; } int main() { fact[0] = 1; for (int i=1;i<100100;i++) fact[i] = fact[i-1] * i % mod; printf ("%lld\n",proc()); return 0; }