#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long table[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
int n, k;
long long power(long long base, int k) {
  long long ans = 1;
  for (; k; k >>= 1) {
    if (k & 1) ans = ans * base % MOD;
    base = base * base % MOD;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  long long ans = power(n - k, n - k) * table[k];
  printf("%d", static_cast<int>(ans % MOD));
}
