#include <bits/stdc++.h>
using namespace std;
int cnt[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
int main() {
  int N, K;
  cin >> N >> K;
  long long int total = 1;
  for (int i = K; i < N; i++) total = total * (N - K) % 1000000007;
  cout << cnt[K] * total % 1000000007 << endl;
  return 0;
}
