#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int n, k;
int p[10];
long long res = 0;
long long modpow(long long a, int b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 1) res = (res * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return res;
}
bool isGood() {
  bool used[10];
  for (int i = 2; i <= k; i++) {
    memset(used, false, sizeof(used));
    bool ok = false;
    for (int j = i;; j = p[j]) {
      if (used[j] == true) break;
      if (j == 1) {
        ok = true;
        break;
      }
      used[j] = true;
    }
    if (ok == false) return false;
  }
  memset(used, false, sizeof(used));
  for (int i = 1;; i = p[i]) {
    if (i == 1 && used[i] == true) return true;
    if (used[i] == true) return false;
    used[i] = true;
  }
}
void rec(int sz) {
  if (sz == k + 1) {
    if (isGood()) {
      res++;
    }
  } else {
    for (int i = 1; i <= k; i++) {
      p[sz] = i;
      rec(sz + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  rec(1);
  cout << (res * modpow((long long)(n - k), n - k)) % mod;
  return 0;
}
