#include <bits/stdc++.h>
const long long num[9] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152},
                mo = 1e9 + 7;
long long n, k, ans = 1;
int main() {
  scanf("%I64d%I64d\n", &n, &k);
  for (int i = 1; i <= n - k; i++) ans = (ans * (n - k)) % mo;
  ans = (ans * num[k]) % mo;
  printf("%I64d", ans);
}
