#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10000005,M=5005,inf=0x3f3f3f3f,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow (int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,fac[N],ifac[N],s[M][M],sum[M],f[M][M],g[M],ans;
void check(int &x,int y){if((x+=y)>=p) x-=p;}
int C(int n,int m){return (n<m) ? 0 : (ll)fac[n]*ifac[m]%p*ifac[n-m]%p;}
int P(int n,int m){return (n<m) ? 0 : (ll)fac[n]*ifac[n-m]%p;}
int main(){
//	freopen("a.in","r",stdin);
	n=read();m=read();
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%p;
	ifac[n]=qpow(fac[n],p-2);
	for (int i=n;i;i--) ifac[i-1]=(ll)ifac[i]*i%p;
	s[0][0]=sum[0]=1;
	for(int i=1;i<=m;i++)
	for(int j=1;j<=i;j++)
		s[i][j]=(s[i-1][j-1]+(ll)(i-1)*s[i-1][j])%p,check(sum[i],s[i][j]);

	f[0][0]=1;
	for (int i=0;i<=m;i++)
	for (int j=0;j<=i;j++){
		check(f[i][j],(ll)g[j]*ifac[m-i]%p);
		if (i!=0)
			check(ans,(ll)f[i][j]*P(n-m,j)%p*P(n-m-j+i-1,n-m-j)%p*sum[max(0,m-i-1)]%p);
		if (i!=m){
			check(f[i+1][j+1],f[i][j]);
			if (i!=0) check(g[j],(ll)f[i-1][j]*fac[m-(i-1)-1]%p);
		}
	}
	printf("%d\n",ans);
	return 0;
}