#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int prec[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const int mod = 1000000000 + 7;
int n, k;
long long doIt(int m, int bse) {
  int b[10];
  for (int i = 0; i < 10; i++) b[i] = 0;
  int res = 0;
  while (!b[m]) {
    int can = true;
    for (int i = 0; i < m && can; i++) {
      int cur = i;
      int iter = m + 1;
      while (iter && cur) {
        cur = b[cur];
        iter--;
      }
      can &= (cur == 0);
    }
    if (can) res++;
    int ind = 0;
    b[ind]++;
    while (b[ind] >= bse) {
      b[ind] = 0;
      ind++;
      b[ind]++;
    }
  }
  return res % mod;
}
int main() {
  cin >> n >> k;
  k = min(k, 8);
  long long res = 1;
  if (k > 1) res = doIt(k, k) % mod;
  for (int i = 0; i < n - k; i++) {
    res = res * 1LL * (n - k);
    res %= mod;
  }
  cout << res << endl;
  return 0;
}
