#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void maximize(T &x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void minimize(T &x, U y) {
  if (x > y) x = y;
}
template <class T>
T Abs(T x) {
  return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x) {
  return sqrt(max(x, (T)0));
}
template <class T, class U, class V>
T addmod(T x, U k, V MOD) {
  return ((x + k) % MOD + MOD) % MOD;
}
template <class T, class U, class V>
T submod(T x, U k, V MOD) {
  return ((x - k) % MOD + MOD) % MOD;
}
template <class T, class U, class V>
T mul(T x, U y, V MOD) {
  return (long long)x * y % MOD;
}
namespace taskD {
const int base = 1e9 + 7;
int n, k;
long long fastExp(long long x, long long h) {
  long long res = 1;
  for (; h > 0; h /= 2, x = mul(x, x, base))
    if (h & 1) res = mul(res, x, base);
  return res;
}
long long solve() {
  scanf("%d%d", &n, &k);
  return mul(fastExp(k, k - 1), fastExp(n - k, n - k), base);
}
}  // namespace taskD
int main(void) { printf("%lld", taskD::solve()); }
