#include <bits/stdc++.h>
using namespace std;
long long cc, mod, sol, n, k;
int a[9], mark[9];
long long PowFast(long long B, long long P, long long MOD) {
  long long R = 1;
  if (P == 0) return R;
  R = PowFast(B, P / 2, MOD);
  R *= R;
  if (R >= MOD) R %= MOD;
  if (P % 2) R *= B;
  if (R >= MOD) R %= MOD;
  return R;
}
bool DoDFS(int nod) {
  if (mark[nod] == 1) return false;
  if (a[nod] == 1) return true;
  mark[nod] = 1;
  return DoDFS(a[nod]);
}
bool Fine() {
  for (int p = (1); p <= (k); p += (1)) mark[p] = 0;
  for (int p = (2); p <= (k); p += (1))
    if (!mark[p]) {
      memset(mark, 0, sizeof(mark));
      if (!DoDFS(p)) return false;
    }
  return true;
}
void COMBINE(int nod) {
  if (nod <= k) {
    for (int p = (1); p <= (k); p += (1))
      if (nod != p) {
        a[nod] = p;
        COMBINE(nod + 1);
      }
  } else {
    if (Fine()) sol += k;
    if (sol >= mod) sol %= mod;
  }
}
void COMPUTE() {
  sol = 0;
  mod = 1000000007;
  cc = PowFast(n - k, n - k, mod);
  COMBINE(2);
  sol *= cc;
  cout << sol % mod;
}
int main() {
  cin >> n >> k;
  COMPUTE();
}
