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