#include <bits/stdc++.h>
#define int long long
#define ls(s) (int)s.size()
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,a,b) for(int i = a;i<=b;++i)
#define tr(it,v) for(auto &it:v)
using namespace std;
const int N = 5005;
const int MOD = 1e9+7;
int dp[N][N];
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
int n,k;
cin >> n >> k;
dp[0][0] = 1;
for(int i = 1;i<=n;++i){
for(int j = 1;j<=min(i,k);++j){
int res1 = dp[i-1][j-1];
int res2 = (dp[i-1][j] * (i-1)) % MOD;
dp[i][j] = (res1 + res2) % MOD;
}
}
cout << dp[n][k];
return 0;
}