#include <bits/stdc++.h>
long long a[] = {0, 1, 1, 3, 16, 125, 1296, 16807, 262144};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long ans = 1;
  for (int i = 0; i < n - k; i++) ans = ans * (n - k) % 1000000007;
  ans = ans * k % 1000000007;
  ans = ans * a[k] % 1000000007;
  printf("%I64d\n", ans);
}
