#include <bits/stdc++.h>
using namespace std;
long long F(int cnt, int head, int tail) {
  if (cnt == 0) return tail == 0 ? 1 : 0;
  return (head * F(cnt - 1, head + tail + 1, 0) +
          (cnt - 1) * F(cnt - 1, head, tail + 1)) %
         1000000007;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int i;
  long long res = F(k - 1, 1, 0) * k % 1000000007;
  for (i = (0); i < (n - k); ++i) res = res * (n - k) % 1000000007;
  printf("%d\n", int(res));
  return 0;
};
