#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c = 1000000007;
  cin >> n >> k;
  long long ans = 1;
  for (int i = 0; i < n - k; i++) ans = (ans * (n - k)) % c;
  ans = (ans * k) % c;
  for (int i = 0; i < k - 2; i++) ans = (ans * k) % c;
  cout << ans << endl;
}
