#include <bits/stdc++.h>
using namespace std;
int n, k;
long long quickpow(long long a, int b) {
  long long now = 1;
  while (b > 0) {
    if (b & 1) (now *= a) %= 1000000007;
    (a *= a) %= 1000000007;
    b >>= 1;
  }
  return now;
}
int main() {
  scanf("%d %d", &n, &k);
  printf("%lld\n", quickpow(k, k - 1) * quickpow(n - k, n - k) % 1000000007);
  return 0;
}
