#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
using namespace std;
const int mo=1000000007;
const int N=10000005;
const int M=5005;
int fac[N],inv[N],Inv[N];
int n,m,f[M][M],g[M][M];
void init(){
	fac[0]=inv[0]=inv[1]=Inv[0]=1;
	For(i,2,N-1) inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
	For(i,1,N-1) Inv[i]=1ll*Inv[i-1]*inv[i]%mo;
	For(i,1,N-1) fac[i]=1ll*fac[i-1]*i%mo;
}
int C(int x,int y){
	return 1ll*fac[x]*Inv[y]%mo*Inv[x-y]%mo;
}
int main(){
	init();
	scanf("%d%d",&n,&m);
	For(i,0,m) f[i][0]=1ll*fac[i+n-m-1]*i%mo;
	For(i,0,m) For(j,1,m-i){
		int val=1ll*f[i][0]*C(i+j,i)%mo;
		f[i+j][0]=(f[i+j][0]+mo-val)%mo;
		f[i+j][j]=val;
	}
	For(i,1,m) For(j,0,m-i){
		g[i][j]=f[i-1][j];
		g[i][j]=(g[i][j]+1ll*g[i-1][j]*(n-m+i-(j+1)))%mo;
		g[i][j]=(g[i][j]+1ll*g[i-1][j+1]*(j+1))%mo;
	}
	int ans=(g[m][0]+f[m][0])%mo;
	cout<<ans<<endl;
}
/*
>_<
*/

