#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k;
  long long mcon = 1000000007;
  long long arr[8] = {1, 2, 9, 64, 625, 7776, 117649, 2097152};
  cin >> n >> k;
  int a = n - k;
  long long pr = 1;
  for (int i = 0; i < a; i++) {
    pr = pr * a;
    if (pr >= mcon) {
      pr = pr % mcon;
    }
  }
  pr = pr * arr[k - 1];
  if (pr >= mcon) {
    pr = pr % mcon;
  }
  cout << pr << endl;
  return 0;
}
