#include <bits/stdc++.h>
const int kMod = 1000000007;
int pm(int a, int b, int m) {
  int ret = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) {
      ret = ret * (long long)a % m;
    }
    a = a * (long long)a % m;
  }
  return ret;
}
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  printf("%d\n", pm(k, k - 1, kMod) * (long long)pm(n - k, n - k, kMod) % kMod);
  return 0;
}
