#include <bits/stdc++.h>
using namespace std;
int m, n, t, k;
long long a[10];
long long x[10];
int cnt;
bool ok(int n) {
  for (int i = 2; i <= n; i++)
    if (a[i] == i) return 0;
  for (int i = 2; i <= n; i++) {
    int t = a[i];
    int cnt = 0;
    while (t != 1) {
      cnt++;
      t = a[t];
      if (cnt > n) return 0;
    }
  }
  return 1;
}
void fun(int n, int cur) {
  if (cur == n + 1) {
    if (ok(n)) cnt++;
    return;
  }
  for (int i = 1; i <= n; ++i) {
    a[cur] = i;
    fun(n, cur + 1);
  }
}
int main() {
  for (int i = 1; i <= 8; i++) {
    cnt = 0;
    fun(i, 2);
    x[i] = cnt;
  }
  scanf("%d%d", &n, &k);
  long long s = n - k;
  long long ans = (x[k] * k) % 1000000007;
  for (int i = 0; i < s; ++i) ans = (ans * s) % 1000000007;
  printf("%I64d\n", ans);
  return 0;
}
