#include <bits/stdc++.h>
const long long bigp = 1000000007;
long long ans, bcj[10];
int getfa(int a) { return bcj[a] == a ? a : getfa(bcj[a]); }
void dfs(int i, int n) {
  if (i == n + 1) {
    ans++;
    return;
  }
  int j;
  for (j = 1; j <= n; ++j)
    if (getfa(j) != getfa(i)) {
      int fai = getfa(i), ori = bcj[fai];
      bcj[fai] = getfa(j);
      dfs(i + 1, n);
      bcj[fai] = ori;
    }
}
int main() {
  int n, k, i, j;
  long long fin = 0;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; ++i) {
    for (j = 1; j <= k; ++j) bcj[j] = j;
    ans = 0;
    dfs(i + 1, k);
    for (j = 1; j < i; ++j) ans = ans * (k - j) % bigp;
    fin = (fin + ans) % bigp;
  }
  for (i = 1; i <= n - k; ++i) fin = fin * (n - k) % bigp;
  printf("%I64d\n", fin);
  return 0;
}
