#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t n, k;
  cin >> n >> k;
  uint64_t prod = 1;
  for (uint64_t i = 0; i < k - 1; i++) {
    prod = (prod * k) % (1000000007ULL);
  }
  for (uint64_t i = 0; i < (n - k); i++) {
    prod = (prod * (n - k)) % (1000000007ULL);
  }
  cout << prod << "\n";
}
