#include using namespace std; using ll = long long; const ll MOD = 1000000007; ll dp[10005], f[10005], fi[10005]; ll modpow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; int k; cin >> n >> k; f[0] = 1; for (int i = 1; i <= k + 1; i++) f[i] = f[i - 1] * i % MOD; fi[k + 1] = modpow(f[k + 1], MOD - 2); for (int i = k + 1; i > 0; i--) fi[i - 1] = fi[i] * i % MOD; auto comb = [&](int r, int c) { return f[r] * fi[c] % MOD * fi[r - c] % MOD; }; dp[0] = n % MOD; for (int i = 1; i <= k; i++) { dp[i] = (modpow((n + 1) % MOD, i + 1) + MOD - 1) % MOD; for (int j = 0; j < i; j++) { (dp[i] += MOD - dp[j] * comb(i + 1, j) % MOD) %= MOD; } (dp[i] *= modpow(i + 1, MOD - 2)) %= MOD; } cout << dp[k] << endl; return 0; }