#include <bits/stdc++.h>
using namespace std;
long long n, i, j, ans, k;
int main() {
  scanf("%I64d%I64d", &n, &k);
  ans = 1;
  for (i = 2; i <= n; i++) {
    if (i == 1)
      ans = (ans * (k - 1)) % 1000000007;
    else if (i <= k)
      ans = (ans * (k)) % 1000000007;
    else
      ans = (ans * (n - k)) % 1000000007;
  }
  printf("%I64d\n", ans);
  return 0;
}
