#include <bits/stdc++.h>
using namespace std;
long long ntree(long long n) {
  if (n == 1) return 1;
  long long ret(1);
  for (int i = 1; i < n; ++i) {
    ret = (ret % (1000000000 + 7) * n) % (1000000000 + 7);
  }
  return ret % (1000000000 + 7);
}
int main(void) {
  long long n, k;
  cin >> n >> k;
  long long m = n - k;
  long long total(ntree(k));
  for (int i = 0; i < m; ++i) {
    total = (total % (1000000000 + 7) * m) % (1000000000 + 7);
  }
  cout << total % (1000000000 + 7) << endl;
  return 0;
}
